Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(skills): correct type definition in skills module

Steven Enamakel5b4c9bba1db7
diff --git a/crates/openhuman-core/src/skills/types.rs b/crates/openhuman-core/src/skills/types.rs
index 5ddabf94c0..4b22dff8d7 100644
--- a/crates/openhuman-core/src/skills/types.rs
+++ b/crates/openhuman-core/src/skills/types.rs
@@ -1,82 +1,7 @@
//! Shared tool result types used by the tool and node runtime surfaces.
//!
//! The definitions live in [`tinytools`]; this module is the stable host import
-//! path for the ~14 call sites that already name it, and the home of the one
-//! conversion that is genuinely ours.
-
-/// Serialized-size ceiling for a pass-through MCP content block before it
-/// reaches a model prompt.
-///
-/// A block kind this build does not model is carried through as JSON rather
-/// than dropped, and the generic payload of such a block can be a base64 image
-/// or audio — megabytes. Above this ceiling the payload is elided, keeping the
-/// block type but not the bytes.
-const MAX_LLM_BLOCK_BYTES: usize = 64 * 1024;
+//! path for the ~14 call sites that already name it. The MCP-result conversion
+//! is `tinymcp::tools::tool_result`.
pub use tinytools::{ToolContent, ToolResult};
-
-/// Converts a rendered MCP result into this application's tool result.
-///
-/// The two shapes are the same by construction — the module's was derived from
-/// this one when the client was extracted — so this is a mapping, not a
-/// translation.
-///
-/// It is a free function rather than a `From` impl because both types are now
-/// foreign to this crate: [`ToolResult`] belongs to `tinytools` and
-/// `McpToolResult` to `tinymcp_bus`, which the orphan rule forbids us from
-/// bridging with a trait impl. The reason the conversion is written **once**
-/// has not changed with its shape: spelled out at each call site, it would be
-/// as many chances to get the error flag the wrong way round.
-pub fn tool_result_from_mcp(result: tinymcp_bus::McpToolResult) -> ToolResult {
- ToolResult {
- content: result
- .content
- .into_iter()
- .map(|block| match block {
- tinymcp_bus::McpToolContent::Text { text } => ToolContent::Text { text },
- tinymcp_bus::McpToolContent::Json { data } => ToolContent::Json { data },
- // The contract's block enum is `#[non_exhaustive]`. A kind this
- // build does not model is carried through as its JSON rather
- // than dropped: a caller can still read it, and dropping it
- // would lose content a server deliberately sent.
- other => ToolContent::Json {
- data: elide_oversized_block(&other),
- },
- })
- .collect(),
- is_error: result.is_error,
- markdown_formatted: result.markdown_formatted,
- // MCP results carry no follow-up, metadata, control or error-kind
- // channels; leave the host-side defaults.
- ..ToolResult::default()
- }
-}
-
-/// Serializes an unrecognized MCP content block, bounding what a model will
-/// see.
-///
-/// The block is kept whole when it is small, so a future payload a server
-/// deliberately sent still reaches the caller. Above [`MAX_LLM_BLOCK_BYTES`]
-/// — the base64 image or audio case — the payload is replaced with an elided
-/// marker while the block type is retained, so a prompt can still tell what
-/// kind of content was dropped.
-fn elide_oversized_block(block: &tinymcp_bus::McpToolContent) -> serde_json::Value {
- let value = serde_json::to_value(block).unwrap_or(serde_json::Value::Null);
- let serialized = serde_json::to_string(&value).unwrap_or_default();
- if serialized.len() <= MAX_LLM_BLOCK_BYTES {
- return value;
- }
-
- let kind = value
- .get("type")
- .cloned()
- .unwrap_or(serde_json::Value::Null);
- serde_json::json!({
- "type": kind,
- "data": format!("[{} bytes elided]", serialized.len()),
- })
-}
-
-#[cfg(test)]
-#[path = "types_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/skills/types_tests.rs b/crates/openhuman-core/src/skills/types_tests.rs
deleted file mode 100644
index 86e6b8e7de..0000000000
--- a/crates/openhuman-core/src/skills/types_tests.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use super::*;
-use serde_json::json;
-
-#[test]
-fn an_mcp_result_maps_across_with_its_error_flag_intact() {
- let ok = tool_result_from_mcp(tinymcp_bus::McpToolResult {
- content: vec![tinymcp_bus::McpToolContent::Text {
- text: "fine".into(),
- }],
- is_error: false,
- markdown_formatted: None,
- });
- assert!(!ok.is_error);
- assert_eq!(ok.text(), "fine");
-
- let failed = tool_result_from_mcp(tinymcp_bus::McpToolResult {
- content: vec![tinymcp_bus::McpToolContent::Text {
- text: "boom".into(),
- }],
- is_error: true,
- markdown_formatted: Some("**boom**".into()),
- });
- assert!(failed.is_error);
- assert_eq!(failed.markdown_formatted.as_deref(), Some("**boom**"));
-}
-
-#[test]
-fn an_oversized_pass_through_block_is_elided_but_keeps_its_type() {
- // A base64 image or audio block can be megabytes; a model should see
- // what kind of block it was, not the bytes.
- let block = tinymcp_bus::McpToolContent::Json {
- data: json!({"base64": "x".repeat(70 * 1024)}),
- };
- let value = elide_oversized_block(&block);
- assert_eq!(value["type"], "json");
- let marker = value["data"].as_str().expect("an elided marker");
- assert!(marker.contains("bytes elided"), "{marker}");
- assert!(!marker.contains("xxxxx"), "the payload must not survive");
-}
-
-#[test]
-fn a_small_pass_through_block_is_carried_whole() {
- let block = tinymcp_bus::McpToolContent::Json {
- data: json!({"n": 42}),
- };
- let value = elide_oversized_block(&block);
- assert_eq!(value, json!({"type": "json", "data": {"n": 42}}));
-}