@@ -30,8 +30,11 @@ interface MothershipEffortState {
3030 chatEfforts : Record < string , ChatEffortPick >
3131 /** Records a pick and returns its token for {@link MothershipEffortState.dropChatEffort}. */
3232 setChatEffort : ( chatId : string , effort : MothershipEffort ) => number
33- /** Drops a pick whose save failed, unless a newer pick replaced it, even one of the same value. */
34- dropChatEffort : ( chatId : string , pick : number ) => void
33+ /**
34+ * Drops a pick whose save failed, unless a newer pick replaced it, even one of the same value.
35+ * Returns whether it dropped the pick, which rolls the chat back to its saved effort.
36+ */
37+ dropChatEffort : ( chatId : string , pick : number ) => boolean
3538 /** Moves the new-chat pick onto the chat its first send created. */
3639 adoptNewChatEffort : ( chatId : string , effort : MothershipEffort ) => void
3740 reset : ( ) => void
@@ -58,7 +61,7 @@ function withModelSelection(
5861export const useMothershipEffortStore = create < MothershipEffortState > ( ) (
5962 devtools (
6063 persist (
61- ( set ) => ( {
64+ ( set , get ) => ( {
6265 ...initialState ,
6366 setFastMode : ( fastMode ) =>
6467 set ( ( state ) => withModelSelection ( { ...state . modelSelection , fastMode } ) ) ,
@@ -70,11 +73,11 @@ export const useMothershipEffortStore = create<MothershipEffortState>()(
7073 set ( ( state ) => ( { chatEfforts : { ...state . chatEfforts , [ chatId ] : { effort, pick } } } ) )
7174 return pick
7275 } ,
73- dropChatEffort : ( chatId , pick ) =>
74- set ( ( state ) => {
75- if ( state . chatEfforts [ chatId ] ?. pick !== pick ) return state
76- return { chatEfforts : omit ( state . chatEfforts , [ chatId ] ) }
77- } ) ,
76+ dropChatEffort : ( chatId , pick ) => {
77+ if ( get ( ) . chatEfforts [ chatId ] ?. pick !== pick ) return false
78+ set ( ( state ) => ( { chatEfforts : omit ( state . chatEfforts , [ chatId ] ) } ) )
79+ return true
80+ } ,
7881 adoptNewChatEffort : ( chatId , effort ) => {
7982 const pick = ++ lastChatEffortPick
8083 set ( ( state ) => ( {
0 commit comments