///|
/// 单序列、有状态的推理 Session。
///
/// 复制 `Session` 会共享同一个 context 和会话状态,不会克隆 KV cache,也不承诺
/// 并发安全。最后一个引用消失后,owner 会自动释放原生 context。
pub struct Session {
  priv owner : SessionOwner
}

///|
/// 返回 llama.cpp 实际采用的 context 容量。
pub fn Session::get_context_size(self : Session) -> UInt {
  @raw.llama_n_ctx(self.owner.get_raw_ref())
}

///|
/// 清空 Session 当前持有的 context memory。
///
/// reset 后同一个 Session 可以从空白上下文重新开始,并从 `NeedsReset` 恢复为
/// `Ready`;重复调用也是安全的。
pub fn Session::reset(self : Session) -> Unit {
  @raw.llama_context_clear_memory(self.owner.get_raw_ref())
  self.owner.reset_used_tokens()
  self.owner.mark_ready()
}