- Type/Function/Variantを Segment* 系へ統一 - SessionId/SessionStart/SessionOrigin/SessionStartState/SessionState/SessionLogSink/SessionLockInfo - new_session_id / session_id / create_session* / list_sessions / lookup_session / update_session / find_by_session - protocol Event::SessionRotated → SegmentRotated、CompactDone.new_session_id → new_segment_id - Module: session_log → segment_log / session → segment (file mv 含む) pod 側の session_log_sink → segment_log_sink も同様 - crate 名 (session-store)、CLI flag (--session)、ResumeWithSession (CLI tied) は据え置き - session-tests/session_metrics_test 等の Store impl も追従
62 lines
2.1 KiB
Rust
62 lines
2.1 KiB
Rust
//! Segment persistence via append-only JSONL logs.
|
|
//!
|
|
//! # Architecture
|
|
//!
|
|
//! Sessions are recorded as a sequence of [`LogEntry`] values, one per line
|
|
//! in a `.jsonl` file. Reading the log and collecting entries reconstructs
|
|
//! the full Worker state — no separate snapshots or checkpoints needed.
|
|
//!
|
|
//! This crate provides free functions for persistence operations.
|
|
//! The caller (typically Pod) holds the Worker directly and calls these
|
|
//! functions after state-mutating operations.
|
|
//!
|
|
//! Debug-mode [`TraceEntry`] records capture raw stream events in a separate
|
|
//! `.trace.jsonl` file, independent of the segment log.
|
|
//!
|
|
//! # Quick start
|
|
//!
|
|
//! ```ignore
|
|
//! use session_store::{create_segment, restore, save_delta, FsStore, SegmentStartState};
|
|
//!
|
|
//! let store = FsStore::new("./sessions")?;
|
|
//! let segment_id = create_segment(&store, SegmentStartState {
|
|
//! system_prompt: None,
|
|
//! config: &config,
|
|
//! history: &[],
|
|
//! })?;
|
|
//! ```
|
|
|
|
pub mod event_trace;
|
|
pub mod fs_store;
|
|
pub mod logged_item;
|
|
pub mod segment;
|
|
pub mod segment_log;
|
|
pub mod store;
|
|
pub mod system_item;
|
|
|
|
pub use event_trace::TraceEntry;
|
|
pub use fs_store::FsStore;
|
|
pub use llm_worker::UsageRecord;
|
|
pub use llm_worker::llm_client::types::{ContentPart, Item, Role};
|
|
pub use logged_item::{LoggedContentPart, LoggedItem, LoggedRole, from_logged, to_logged};
|
|
pub use segment::{
|
|
SegmentStartState, append_entry, append_system_item, classify_history_item,
|
|
create_compacted_segment, create_segment, create_segment_with_id, ensure_head_or_fork, fork,
|
|
fork_at, restore, save_config_changed, save_delta, save_extension, save_pod_scope,
|
|
save_run_completed, save_run_errored, save_turn_end, save_usage, save_user_input,
|
|
};
|
|
pub use segment_log::{
|
|
LogEntry, POD_SCOPE_EXTENSION_DOMAIN, PodScopeSnapshot, RestoredState, SegmentOrigin,
|
|
collect_state,
|
|
};
|
|
pub use system_item::{SystemItem, render_pod_event};
|
|
pub use store::{Store, StoreError};
|
|
|
|
/// Segment identifier. UUID v7 (time-ordered, lexicographically sortable).
|
|
pub type SegmentId = uuid::Uuid;
|
|
|
|
/// Generate a new segment ID.
|
|
pub fn new_segment_id() -> SegmentId {
|
|
uuid::Uuid::now_v7()
|
|
}
|