Session ops and ContextPolicy in hx-core
This commit is contained in:
1 parent
69d5ae4581
commit
be74dd9fec
7 files changed
+205
-105
No files matched your search
+10
-18
@@ -685,10 +685,12 @@ async fn main() -> Result<()> {
|
||||
if let Some(n) = cfg.max_tokens {
|
||||
agent.set_max_tokens(n);
|
||||
}
|
||||
match cfg.compact_at {
|
||||
Some(n) => agent.set_compact_at(n),
|
||||
None => agent.fit_window(hx_ai::models::window(&models, agent.model())),
|
||||
}
|
||||
agent.set_context_policy(match cfg.compact_at {
|
||||
Some(n) => hx_core::window::ContextPolicy::Fixed(n),
|
||||
None => hx_core::window::ContextPolicy::FromModel {
|
||||
window: hx_ai::models::window(&models, agent.model()),
|
||||
},
|
||||
});
|
||||
let exts = futures::future::join_all(cfg.extensions.iter().map(|e| async {
|
||||
hx_core::ext::Extension::start(e, &cwd)
|
||||
.await
|
||||
@@ -802,13 +804,8 @@ async fn main() -> Result<()> {
|
||||
specs,
|
||||
files: hx_tui::project_files(&cwd),
|
||||
session_dir: dir,
|
||||
switcher: Switcher::new(
|
||||
kind,
|
||||
models.clone(),
|
||||
Box::new(provider),
|
||||
cfg.compact_at.is_none(),
|
||||
)
|
||||
.remember_in(last_path.clone(), start.clone()),
|
||||
switcher: Switcher::new(kind, models.clone(), Box::new(provider))
|
||||
.remember_in(last_path.clone(), start.clone()),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -822,13 +819,8 @@ async fn main() -> Result<()> {
|
||||
let Some(prompt) = cli.print else {
|
||||
hx_tui::run(hx_tui::Setup {
|
||||
agent,
|
||||
switcher: Switcher::new(
|
||||
kind,
|
||||
models.clone(),
|
||||
Box::new(provider),
|
||||
cfg.compact_at.is_none(),
|
||||
)
|
||||
.remember_in(last_path, start),
|
||||
switcher: Switcher::new(kind, models.clone(), Box::new(provider))
|
||||
.remember_in(last_path, start),
|
||||
pricing,
|
||||
specs,
|
||||
open_sessions,
|
||||
|
||||
@@ -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()),
|
||||
|
||||
Reference in new issue
Block a user