Skip to content

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

refactor(tokenjuice): replace duplicated wire types with tinyjuice-bus re-exports\n\nThe module previously maintained its own copies of wire types that were shared by convention with the TinyJuice module, creating a maintenance hazard where changes on one side could silently break the other. These types are now re-exported from the `tinyjuice-bus` crate, which serves as the single source of truth for the contract, while preserving the existing paths used by call sites throughout the crate.\n\nAuto-committed-on: dragonfly\n

Steven Enamakelbd55acb675f9
diff --git a/src/openhuman/inference/tokenjuice/types.rs b/src/openhuman/inference/tokenjuice/types.rs
index 89b143731f..72ca1542b9 100644
--- a/src/openhuman/inference/tokenjuice/types.rs
+++ b/src/openhuman/inference/tokenjuice/types.rs
@@ -1,214 +1,25 @@
-//! Stable wire types shared with the separately compiled TinyJuice module.
-
-use serde::{Deserialize, Serialize};
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
-#[serde(rename_all = "snake_case")]
-pub enum AgentTokenjuiceCompression {
- #[default]
- Auto,
- Full,
- Light,
- Off,
-}
-
-impl AgentTokenjuiceCompression {
- pub fn as_str(self) -> &'static str {
- match self {
- Self::Auto => "auto",
- Self::Full => "full",
- Self::Light => "light",
- Self::Off => "off",
- }
- }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub enum ContentKind {
- Json,
- Code,
- Log,
- Search,
- Diff,
- Html,
- PlainText,
-}
-
-impl ContentKind {
- pub fn as_str(self) -> &'static str {
- match self {
- Self::Json => "json",
- Self::Code => "code",
- Self::Log => "log",
- Self::Search => "search",
- Self::Diff => "diff",
- Self::Html => "html",
- Self::PlainText => "plain_text",
- }
- }
-}
-
-impl std::str::FromStr for ContentKind {
- type Err = ();
- fn from_str(value: &str) -> Result<Self, Self::Err> {
- Ok(match value {
- "json" => Self::Json,
- "code" => Self::Code,
- "log" => Self::Log,
- "search" => Self::Search,
- "diff" => Self::Diff,
- "html" => Self::Html,
- "plain_text" => Self::PlainText,
- _ => return Err(()),
- })
- }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub enum CompressorKind {
- SmartCrusher,
- Code,
- Log,
- Search,
- Diff,
- Html,
- MlText,
- Generic,
- None,
-}
-
-impl CompressorKind {
- pub fn as_str(self) -> &'static str {
- match self {
- Self::SmartCrusher => "smartcrusher",
- Self::Code => "code",
- Self::Log => "log",
- Self::Search => "search",
- Self::Diff => "diff",
- Self::Html => "html",
- Self::MlText => "ml_text",
- Self::Generic => "generic",
- Self::None => "none",
- }
- }
-}
-
-impl std::str::FromStr for CompressorKind {
- type Err = ();
- fn from_str(value: &str) -> Result<Self, Self::Err> {
- Ok(match value {
- "smartcrusher" => Self::SmartCrusher,
- "code" => Self::Code,
- "log" => Self::Log,
- "search" => Self::Search,
- "diff" => Self::Diff,
- "html" => Self::Html,
- "ml_text" => Self::MlText,
- "generic" => Self::Generic,
- "none" => Self::None,
- _ => return Err(()),
- })
- }
-}
-
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ContentHint {
- pub mime: Option<String>,
- pub extension: Option<String>,
- pub source_tool: Option<String>,
- pub query: Option<String>,
- pub explicit: Option<ContentKind>,
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase", default)]
-pub struct CompressOptions {
- pub router_enabled: bool,
- pub ccr_enabled: bool,
- pub search_enabled: bool,
- pub code_enabled: bool,
- pub html_enabled: bool,
- pub ml_text_enabled: bool,
- pub min_bytes_to_compress: usize,
- pub min_bytes_to_compress_log: usize,
- pub ccr_min_tokens: usize,
- pub lossy_without_ccr: bool,
- pub max_inline_chars: Option<usize>,
- pub code_target_ratio: Option<f32>,
- pub chars_per_token: f32,
-}
-
-impl Default for CompressOptions {
- fn default() -> Self {
- Self {
- router_enabled: true,
- ccr_enabled: true,
- search_enabled: true,
- code_enabled: true,
- html_enabled: true,
- ml_text_enabled: false,
- min_bytes_to_compress: 2048,
- min_bytes_to_compress_log: 512,
- ccr_min_tokens: 500,
- lossy_without_ccr: false,
- max_inline_chars: None,
- code_target_ratio: None,
- chars_per_token: 4.0,
- }
- }
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CompressedOutput {
- pub text: String,
- pub content_kind: ContentKind,
- pub compressor: CompressorKind,
- pub lossy: bool,
- pub applied: bool,
- pub ccr_token: Option<String>,
- pub original_bytes: usize,
- pub compacted_bytes: usize,
-}
-
-#[derive(Debug, Clone, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CompactResponse {
- pub text: String,
- pub original_bytes: usize,
- pub compacted_bytes: usize,
- pub rule_id: String,
- pub applied: bool,
- pub content_kind: String,
- pub compressor: String,
- pub original_tokens: u64,
- pub compacted_tokens: u64,
-}
-
-#[derive(Debug, Clone, Copy, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub enum RangeUnit {
- Bytes,
- Lines,
-}
-
-#[derive(Debug, Clone, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct RetrieveRange {
- pub start: usize,
- pub end: usize,
- pub unit: RangeUnit,
-}
-
-#[derive(Debug, Clone, Copy, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CacheStats {
- pub entries: usize,
- pub bytes: usize,
-}
+//! The wire types shared with the separately compiled TinyJuice module.
+//!
+//! These were declared here — 259 lines of them, under a doc comment saying
+//! they were "shared with" the module. They were shared by convention: the
+//! module's copy was private to its adapter and the library's copy was the
+//! library's, so neither was reachable from here and nothing checked that the
+//! three agreed. A field added on one side was a decode failure on the other.
+//!
+//! `tinyjuice-bus` is that contract as an ordinary crate, and this module is a
+//! re-export of it. The names below are the ones ~40 call sites in this crate
+//! already use, so the paths are unchanged.
+//!
+//! `RangeUnit`, `RetrieveRange` and `CacheStats` come from the contract's
+//! `wire` module rather than its `types` module — the split there is between
+//! values the `tinyjuice` library itself uses and envelopes that exist only on
+//! the bus. Nothing here needs to care which is which.
+
+pub use tinyjuice_bus::types::{
+ AgentTokenjuiceCompression, CompressOptions, CompressedOutput, CompressorKind, ContentHint,
+ ContentKind,
+};
+pub use tinyjuice_bus::wire::{CacheStats, CompactResponse, InstallRequest, RangeUnit, RetrieveRange};
#[cfg(test)]
mod tests {