Skip to content

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

refactor(web_chat): move turn citations out of memory module

Steven Enamakel8134431e9ba9
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks.rs b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
index c25055782c..3916f723bc 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
@@ -52,7 +52,7 @@ pub struct TurnPack {
pub engine: String,
/// The cited items, for the chat's memory chips.
#[serde(skip)]
- pub citations: Vec<crate::memory::types::TurnCitation>,
+ pub citations: Vec<crate::web_chat::TurnCitation>,
/// Set when nothing was recalled because the engine refused the whole
/// account (a `MemoryError` code such as `INSUFFICIENT_CREDITS`): the
/// block is then a notice saying so, not recalled memory.
@@ -70,7 +70,7 @@ impl TurnPack {
.iter()
.flat_map(|section| section.hits.iter())
.filter(|hit| pack.refs.contains(&hit.id))
- .map(crate::memory::types::TurnCitation::from)
+ .map(crate::web_chat::TurnCitation::from)
.collect();
Some(Self {
markdown: pack.markdown,
diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
index ec567cf684..218614962c 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
@@ -199,7 +199,7 @@ pub(crate) fn pre_turn(
let pack = identity.recall.then(|| completed(&cache, &key)).flatten();
tracing::debug!(thread_id = %key.thread, agent_id = %key.identity.agent_id, cache_hit = pack.is_some(), "[memory:prefetch] pre_turn cache");
if let Some(pack) = &pack {
- crate::memory::tools::record_pack_citations(ctx, &thread_id, pack.citations.clone());
+ crate::web_chat::citations::record_pack_citations(ctx, &thread_id, pack.citations.clone());
}
let dispatch = ctx.clone();
enqueue(
diff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rs
index 4ab166bd5f..f2bda2f40c 100644
--- a/crates/openhuman-core/src/memory/tools_agent_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs
@@ -126,7 +126,7 @@ fn turn_citations_are_capped_and_deduplicated() {
MAX_TURN_CITATIONS
);
assert!(
- drained[0].snippet.chars().count() <= crate::memory::types::TURN_CITATION_SNIPPET_CHARS
+ drained[0].snippet.chars().count() <= crate::web_chat::TURN_CITATION_SNIPPET_CHARS
);
assert_eq!(drained[0].key, "learning");
}
diff --git a/crates/openhuman-core/src/web_chat/presentation.rs b/crates/openhuman-core/src/web_chat/presentation.rs
index 2a44d9e2b8..c9ce846635 100644
--- a/crates/openhuman-core/src/web_chat/presentation.rs
+++ b/crates/openhuman-core/src/web_chat/presentation.rs
@@ -53,7 +53,7 @@ pub(crate) async fn deliver_response(
request_id: &str,
full_response: &str,
user_message: &str,
- citations: &[crate::memory::types::TurnCitation],
+ citations: &[crate::web_chat::TurnCitation],
usage: Option<&LastTurnUsage>,
workspace_dir: Option<&std::path::Path>,
timing: Option<super::turn_timing::TurnTimingSnapshot>,
@@ -91,7 +91,7 @@ pub(crate) async fn persist_reply(
thread_id: &str,
request_id: &str,
full_response: &str,
- citations: &[crate::memory::types::TurnCitation],
+ citations: &[crate::web_chat::TurnCitation],
workspace_dir: Option<&std::path::Path>,
) {
if let Some(dir) = workspace_dir {
@@ -147,7 +147,7 @@ pub(crate) fn announce_reply(
request_id: &str,
full_response: &str,
user_message: &str,
- citations: &[crate::memory::types::TurnCitation],
+ citations: &[crate::web_chat::TurnCitation],
usage: Option<&LastTurnUsage>,
timing: Option<super::turn_timing::TurnTimingSnapshot>,
suggest_follow_ups: bool,
@@ -215,7 +215,7 @@ fn publish_chat_done(
thread_id: &str,
request_id: &str,
full_response: &str,
- citations: &[crate::memory::types::TurnCitation],
+ citations: &[crate::web_chat::TurnCitation],
usage_payload: Option<TurnUsagePayload>,
timing_payload: Option<crate::web_chat::TurnTimingPayload>,
) {
diff --git a/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs b/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
index 2d99b48097..d938136ba9 100644
--- a/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_test_support_tests.rs
@@ -1,4 +1,4 @@
-use crate::memory::types::TurnCitation;
+use crate::web_chat::TurnCitation;
pub async fn deliver_response_for_test(
client_id: &str,
diff --git a/crates/openhuman-core/src/web_chat/presentation_tests.rs b/crates/openhuman-core/src/web_chat/presentation_tests.rs
index 70389f8645..1691c400ab 100644
--- a/crates/openhuman-core/src/web_chat/presentation_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_tests.rs
@@ -155,7 +155,7 @@ async fn delivery_stores_the_reply_before_announcing_it() {
)
.expect("thread created");
- let citation = crate::memory::types::TurnCitation {
+ let citation = crate::web_chat::TurnCitation {
id: "mem-deliver".to_string(),
key: "summary-source".to_string(),
namespace: None,
diff --git a/crates/openhuman-core/src/web_chat/reply_persistence.rs b/crates/openhuman-core/src/web_chat/reply_persistence.rs
index ada4666bbb..cbc4542c99 100644
--- a/crates/openhuman-core/src/web_chat/reply_persistence.rs
+++ b/crates/openhuman-core/src/web_chat/reply_persistence.rs
@@ -23,7 +23,7 @@ use std::path::Path;
use serde_json::json;
-use crate::memory::types::TurnCitation;
+use crate::web_chat::TurnCitation;
use crate::threads::store::{self as conversations, run_reply_message_id, ConversationMessage};
/// Metadata scope stamped on a reply persisted by the web-channel delivery path.
diff --git a/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs b/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs
index 16d1599271..cc4981d6c9 100644
--- a/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs
+++ b/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use super::persist_delivered_reply;
-use crate::memory::types::TurnCitation;
+use crate::web_chat::TurnCitation;
use crate::threads::store::{self as conversations, CreateConversationThread};
fn temp_ws() -> PathBuf {
diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rs
index 6f37fa2469..65c82f4863 100644
--- a/crates/openhuman-core/src/web_chat/run_task.rs
+++ b/crates/openhuman-core/src/web_chat/run_task.rs
@@ -215,7 +215,7 @@ pub(crate) async fn run_chat_task(
// any stale budget-exhausted signal before it could mislabel a
// later genuine empty response. See #3386.
super::ops::clear_budget_signal(ctx, thread_id).await;
- let citations = crate::memory::tools::take_turn_citations(ctx, thread_id);
+ let citations = crate::web_chat::citations::take_turn_citations(ctx, thread_id);
let usage = agent.take_last_turn_usage_totals();
Ok(WebChatTaskResult {
full_response: response,
diff --git a/crates/openhuman-core/src/web_chat/types.rs b/crates/openhuman-core/src/web_chat/types.rs
index 4cf866af3f..5c34d7da7a 100644
--- a/crates/openhuman-core/src/web_chat/types.rs
+++ b/crates/openhuman-core/src/web_chat/types.rs
@@ -120,7 +120,7 @@ pub(super) struct ParallelEntry {
#[derive(Debug, Clone)]
pub(super) struct WebChatTaskResult {
pub(super) full_response: String,
- pub(super) citations: Vec<crate::memory::types::TurnCitation>,
+ pub(super) citations: Vec<crate::web_chat::TurnCitation>,
/// Holistic token/cost/context totals for the turn (parent + sub-agents),
/// forwarded to the frontend on `chat_done`. `None` for synthetic results
/// (e.g. budget-exhausted placeholders) that never ran a real turn.