refactor: Podのメインループのリファクタリング
This commit is contained in:
@@ -39,10 +39,10 @@ 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 session::{
|
||||
SessionStartState, create_compacted_session, create_session, create_session_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,
|
||||
SessionStartState, append_entry, append_entry_with_hash, create_compacted_session,
|
||||
create_session, create_session_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 session_log::{
|
||||
EntryHash, HashedEntry, LogEntry, POD_SCOPE_EXTENSION_DOMAIN, PodScopeSnapshot, RestoredState,
|
||||
|
||||
@@ -457,14 +457,31 @@ pub async fn fork_at(
|
||||
Ok(fork_id)
|
||||
}
|
||||
|
||||
// ── Private helper ──────────────────────────────────────────────────────
|
||||
|
||||
async fn append_entry(
|
||||
/// Append a single `LogEntry`, chaining the hash and updating `head_hash`.
|
||||
///
|
||||
/// Lower-level dual of the `save_*` convenience wrappers in this module.
|
||||
/// Use when the caller already builds the typed entry itself (e.g. when
|
||||
/// it needs the same value for an in-memory mirror + broadcast).
|
||||
pub async fn append_entry(
|
||||
store: &impl Store,
|
||||
session_id: SessionId,
|
||||
head_hash: &mut Option<EntryHash>,
|
||||
entry: LogEntry,
|
||||
) -> Result<(), StoreError> {
|
||||
append_entry_with_hash(store, session_id, head_hash, entry).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Same as [`append_entry`] but returns the freshly computed entry hash.
|
||||
///
|
||||
/// Used by paths that need the hash for downstream broadcast or mirror
|
||||
/// updates (e.g. the Pod's `SessionLogSink`).
|
||||
pub async fn append_entry_with_hash(
|
||||
store: &impl Store,
|
||||
session_id: SessionId,
|
||||
head_hash: &mut Option<EntryHash>,
|
||||
entry: LogEntry,
|
||||
) -> Result<EntryHash, StoreError> {
|
||||
let hash = session_log::compute_hash(head_hash.as_ref(), &entry);
|
||||
let hashed_entry = HashedEntry {
|
||||
hash: hash.clone(),
|
||||
@@ -472,6 +489,6 @@ async fn append_entry(
|
||||
entry,
|
||||
};
|
||||
store.append(session_id, &hashed_entry).await?;
|
||||
*head_hash = Some(hash);
|
||||
Ok(())
|
||||
*head_hash = Some(hash.clone());
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user