a5cf04b325
Resume GPT sessions when the last assistant reply ends in a permission-seeking tail, while honoring stop-continuation and avoiding duplicate continuation across todo and atlas flows. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
35 lines
868 B
TypeScript
35 lines
868 B
TypeScript
type SessionState = {
|
|
inFlight: boolean
|
|
lastHandledMessageID?: string
|
|
lastInjectedAt?: number
|
|
}
|
|
|
|
export type SessionStateStore = ReturnType<typeof createSessionStateStore>
|
|
|
|
export function createSessionStateStore() {
|
|
const states = new Map<string, SessionState>()
|
|
|
|
const getState = (sessionID: string): SessionState => {
|
|
const existing = states.get(sessionID)
|
|
if (existing) return existing
|
|
|
|
const created: SessionState = {
|
|
inFlight: false,
|
|
}
|
|
states.set(sessionID, created)
|
|
return created
|
|
}
|
|
|
|
return {
|
|
getState,
|
|
wasRecentlyInjected(sessionID: string, windowMs: number): boolean {
|
|
const state = states.get(sessionID)
|
|
if (!state?.lastInjectedAt) return false
|
|
return Date.now() - state.lastInjectedAt <= windowMs
|
|
},
|
|
cleanup(sessionID: string): void {
|
|
states.delete(sessionID)
|
|
},
|
|
}
|
|
}
|