Skip to content

Commit 60017ee

Browse files
committed
fix(plan): trigger StateFlow update after plan changes
Update the plan instance with a new timestamp to ensure StateFlow emits changes when task or step status is updated.
1 parent 6648ccf commit 60017ee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/plan/PlanStateService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class PlanStateService {
9494
val plan = _currentPlan.value ?: return
9595
val task = plan.getTask(taskId) ?: return
9696
task.updateStatus(status)
97+
// Trigger StateFlow update by creating a new plan instance with updated timestamp
98+
_currentPlan.value = plan.copy(updatedAt = kotlinx.datetime.Clock.System.now().toEpochMilliseconds())
9799
notifyTaskUpdated(task)
98100
}
99101

@@ -103,6 +105,8 @@ class PlanStateService {
103105
fun completeStep(taskId: String, stepId: String) {
104106
val plan = _currentPlan.value ?: return
105107
plan.completeStep(taskId, stepId)
108+
// Trigger StateFlow update by creating a new plan instance with updated timestamp
109+
_currentPlan.value = plan.copy(updatedAt = kotlinx.datetime.Clock.System.now().toEpochMilliseconds())
106110
notifyStepCompleted(taskId, stepId)
107111
}
108112

@@ -113,6 +117,8 @@ class PlanStateService {
113117
val plan = _currentPlan.value ?: return
114118
val task = plan.getTask(taskId) ?: return
115119
task.updateStepStatus(stepId, status)
120+
// Trigger StateFlow update by creating a new plan instance with updated timestamp
121+
_currentPlan.value = plan.copy(updatedAt = kotlinx.datetime.Clock.System.now().toEpochMilliseconds())
116122
notifyTaskUpdated(task)
117123
}
118124

0 commit comments

Comments
 (0)