feat(runtime): preserve current branch context

This commit is contained in:
2026-07-28 22:52:06 +08:00
parent 37b3397e4a
commit d0612b399c
8 changed files with 1418 additions and 85 deletions
+41 -19
View File
@@ -24,9 +24,10 @@ use nana_engine::{
SceneMetadata, StoryNodePlayerViewProjectionContext, project_story_node_player_view,
};
use nana_runtime::{
AdjudicatingTurnPlanProvider, AdjudicationCatalog, LappAdjudicationModel, LappNativeCallGate,
LappNativeCallPermit, OpenLappChatExecutor, ProviderError, TurnControl, TurnEngine, TurnPlan,
TurnPlanProvider, TurnProjector, load_default_lapp_profile,
AdjudicatingTurnPlanProvider, AdjudicationCatalog, BranchHistoryProjection,
LappAdjudicationModel, LappNativeCallGate, LappNativeCallPermit, OpenLappChatExecutor,
ProviderError, TurnControl, TurnEngine, TurnPlan, TurnPlanProvider, TurnProjector,
load_default_lapp_profile,
};
use nana_store::{ForkError, SqliteStoryStore, StoreError, StoredBranch, StoryStore};
use openlapp::{
@@ -359,6 +360,41 @@ impl TurnPlanProvider for RuntimePlanProvider {
Self::RetiredTest => Err(ProviderError::Cancelled),
}
}
fn plan_turn_with_history(
&mut self,
request: &TurnRequest,
state: &RuntimeState,
branch_history: &BranchHistoryProjection,
) -> Result<TurnPlan, ProviderError> {
match self {
Self::Demo(provider) => provider.plan_turn_with_history(request, state, branch_history),
Self::Lapp(provider) => provider.plan_turn_with_history(request, state, branch_history),
Self::Unavailable => Err(ProviderError::Configuration { code: None }),
#[cfg(test)]
Self::RetiredTest => Err(ProviderError::Cancelled),
}
}
fn plan_turn_with_history_and_control(
&mut self,
request: &TurnRequest,
state: &RuntimeState,
branch_history: &BranchHistoryProjection,
control: &TurnControl,
) -> Result<TurnPlan, ProviderError> {
match self {
Self::Demo(provider) => {
provider.plan_turn_with_history_and_control(request, state, branch_history, control)
}
Self::Lapp(provider) => {
provider.plan_turn_with_history_and_control(request, state, branch_history, control)
}
Self::Unavailable => Err(ProviderError::Configuration { code: None }),
#[cfg(test)]
Self::RetiredTest => Err(ProviderError::Cancelled),
}
}
}
impl DemoAppState {
@@ -905,22 +941,8 @@ impl DemoAppState {
}
fn load_lineage(&self, current: &StoryNode) -> Result<Vec<StoryNode>, StoreError> {
let mut lineage = vec![current.clone()];
let mut cursor = current.parent_id.clone();
while let Some(ref node_id) = cursor {
if lineage.len() >= 200 {
return Err(StoreError::StateMismatch(
"story lineage exceeds the projection limit",
));
}
let node = self.store.load_node(&current.story_id, node_id)?;
cursor.clone_from(&node.parent_id);
lineage.push(node);
}
lineage.reverse();
Ok(lineage)
self.store
.load_ancestor_chain(&current.story_id, &current.id)
}
}