MCPcopy Create free account
hub / github.com/Louisym/MiniCC / save_session_json

Function save_session_json

tutorials/12_session_persistence.py:237–253  ·  view source on GitHub ↗

整文件 JSON 保存。 对应源码: session.rs:88-91 pub fn save_to_path(&self, path) -> Result<(), SessionError> { fs::write(path, self.to_json().render())?; Ok(()) }

(session: Session, path: str)

Source from the content-addressed store, hash-verified

235# 这是 Rust 源码中实际实现的方式(简单但有局限)
236
237def save_session_json(session: Session, path: str):
238 """
239 整文件 JSON 保存。
240
241 对应源码: session.rs:88-91
242 pub fn save_to_path(&self, path) -> Result<(), SessionError> {
243 fs::write(path, self.to_json().render())?;
244 Ok(())
245 }
246 """
247 data = {
248 "version": session.version,
249 "session_id": session.session_id,
250 "messages": [m.to_dict() for m in session.messages],
251 }
252 with open(path, "w") as f:
253 json.dump(data, f, indent=2, ensure_ascii=False)
254
255
256def load_session_json(path: str) -> Session:

Callers 1

mainFunction · 0.85

Calls 1

to_dictMethod · 0.45

Tested by

no test coverage detected