Session ops and ContextPolicy in hx-core

This commit is contained in:
hermes committed 2026-10-09 19:34:59 +00:00
1 parent 69d5ae4581
commit be74dd9fec
7 files changed
+205 -105

No files matched your search

+6 -13
View File
@@ -137,9 +137,8 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()>
Some(n) if a.fork(n) => Ok(json!({"head": a.session().head()})),
_ => Err("unknown entry id".into()),
},
"clear" => a
.clear()
.map(|_| json!({}))
"clear" | "new" => a.new_session_here()
.map(|_| json!({"session": a.session().path()}))
.map_err(|e| e.to_string()),
"set_model" => match p["model"].as_str() {
// switches provider too when the model belongs to another one
@@ -155,7 +154,7 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()>
None => Err("params.model required".into()),
},
"compact" => a
.compact(4)
.compact_now()
.await
.map(|c| json!({"compacted": c}))
.map_err(|e| e.to_string()),
@@ -171,16 +170,10 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()>
"modified": m.modified.duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_secs()),
})).collect::<Vec<_>>()))
}
"new" => hx_core::session::Session::open(hx_core::session::new_path(&session_dir))
.map(|s| {
a.replace_session(s);
json!({"session": a.session().path()})
})
.map_err(|e| e.to_string()),
"resume" => match p["path"].as_str() {
Some(path) => hx_core::session::Session::open(path)
.map(|s| {
a.replace_session(s);
Some(path) => a
.resume(std::path::Path::new(path))
.map(|_| {
json!({"session": a.session().path(), "messages": a.session().messages().len()})
})
.map_err(|e| e.to_string()),