The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore(channels): remove unused relay store module
Steven Enamakelcf22a73d8cd2
diff --git a/crates/openhuman-core/src/channels/providers/relay/store.rs b/crates/openhuman-core/src/channels/providers/relay/store.rsnew file mode 100644index 0000000000..3d1b2d1023--- /dev/null+++ b/crates/openhuman-core/src/channels/providers/relay/store.rs@@ -0,0 +1,152 @@+//! The relayed conversation on disk: the thread, the inbound message, the+//! reply, and the history a turn is seeded from.+//!+//! Everything is written to the workspace of the config the caller's context+//! loads, so a SaaS user's relayed thread lives with their web threads. The+//! process-wide channel persistence subscriber is told to leave these turns+//! alone (`threads::store::claim_channel_turn`).++use std::path::Path;++use chrono::Utc;+use serde_json::json;+use tinyagents_session::transcript::TranscriptMessage;++use super::params::RelayInboundParams;+use crate::threads::store::blocking as conversations;+use crate::threads::store::{ConversationMessage, CreateConversationThread};++/// Whether an inbound message was new to its thread.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum Recorded {+ New,+ /// Already on the thread: a gateway retry. No turn runs for it.+ Duplicate,+}++/// The stored id of the inbound message.+pub fn inbound_message_id(message_id: &str) -> String {+ format!("user:{message_id}")+}++/// The stored id of the reply to it.+pub fn reply_message_id(message_id: &str) -> String {+ format!("assistant:{message_id}")+}++/// Create the thread if needed and append the inbound message, unless it is+/// already there.+pub async fn record_inbound(+ workspace_dir: &Path,+ params: &RelayInboundParams,+ thread_id: &str,+) -> Result<Recorded, String> {+ let now = Utc::now().to_rfc3339();+ conversations::ensure_thread(+ workspace_dir.to_path_buf(),+ CreateConversationThread {+ id: thread_id.to_string(),+ title: params.thread_title(),+ created_at: now.clone(),+ parent_thread_id: None,+ labels: Some(vec!["general".to_string()]),+ personality_id: None,+ working_dir: None,+ },+ )+ .await?;++ let id = inbound_message_id(¶ms.message_id);+ let existing =+ conversations::get_messages(workspace_dir.to_path_buf(), thread_id.to_string()).await?;+ if existing.iter().any(|message| message.id == id) {+ return Ok(Recorded::Duplicate);+ }+ conversations::append_message(+ workspace_dir.to_path_buf(),+ thread_id.to_string(),+ ConversationMessage {+ id,+ content: params.text.clone(),+ message_type: "text".to_string(),+ extra_metadata: json!({+ "scope": "channel",+ "channel": params.channel,+ "channelSender": params.sender_id,+ "channelSenderName": params.sender_name,+ "replyTarget": params.chat_id,+ "sourceEvent": "channel_relay_inbound",+ "sourceMessageId": params.message_id,+ }),+ sender: "user".to_string(),+ created_at: now,+ },+ )+ .await?;+ Ok(Recorded::New)+}++/// Append the turn's reply: every text the relay sink sent, in order.+pub async fn record_reply(+ workspace_dir: &Path,+ params: &RelayInboundParams,+ thread_id: &str,+ replies: &[String],+) -> Result<(), String> {+ if replies.is_empty() {+ return Ok(());+ }+ conversations::append_message(+ workspace_dir.to_path_buf(),+ thread_id.to_string(),+ ConversationMessage {+ id: reply_message_id(¶ms.message_id),+ content: replies.join("\n\n"),+ message_type: "text".to_string(),+ extra_metadata: json!({+ "scope": "channel",+ "channel": params.channel,+ "replyTarget": params.chat_id,+ "sourceEvent": "channel_relay_reply",+ "sourceMessageId": params.message_id,+ }),+ sender: "assistant".to_string(),+ created_at: Utc::now().to_rfc3339(),+ },+ )+ .await?;+ Ok(())+}++/// The thread's earlier turns as the channel pipeline's per-chat history:+/// user and assistant rows before `message_id`, the most recent `limit`.+pub async fn prior_turns(+ workspace_dir: &Path,+ thread_id: &str,+ message_id: &str,+ limit: usize,+) -> Result<Vec<TranscriptMessage>, String> {+ let current = inbound_message_id(message_id);+ let messages =+ conversations::get_messages(workspace_dir.to_path_buf(), thread_id.to_string()).await?;+ let rows = to_history(&messages, ¤t);+ let skip = rows.len().saturating_sub(limit);+ Ok(rows.into_iter().skip(skip).collect())+}++/// `messages` up to (not including) the one with id `current`, as history.+fn to_history(messages: &[ConversationMessage], current: &str) -> Vec<TranscriptMessage> {+ messages+ .iter()+ .take_while(|message| message.id != current)+ .filter_map(|message| match message.sender.as_str() {+ "user" => Some(TranscriptMessage::user(&message.content)),+ "assistant" => Some(TranscriptMessage::assistant(&message.content)),+ _ => None,+ })+ .collect()+}++#[cfg(test)]+#[path = "store_tests.rs"]+mod tests;