mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 10:11:46 +03:00
feat(tui): make follow-up queue explicit
This commit is contained in:
+6
-10
@@ -5,10 +5,9 @@ export interface QueuedPrompt {
|
||||
options: MessageOptions
|
||||
}
|
||||
|
||||
/** Owns the difference between steering the active turn and starting the next one. */
|
||||
/** Owns prompts that should start after the active turn finishes. */
|
||||
export class PromptQueue {
|
||||
private prompts: QueuedPrompt[] = []
|
||||
private armed = false
|
||||
|
||||
get length(): number {
|
||||
return this.prompts.length
|
||||
@@ -16,30 +15,27 @@ export class PromptQueue {
|
||||
|
||||
enqueue(prompt: QueuedPrompt): void {
|
||||
this.prompts.push(prompt)
|
||||
this.armed = true
|
||||
}
|
||||
|
||||
/** A second Enter immediately promotes the newest queued prompt to steering. */
|
||||
takeSteering(): QueuedPrompt | null {
|
||||
if (!this.armed) return null
|
||||
this.armed = false
|
||||
takeLast(): QueuedPrompt | null {
|
||||
return this.prompts.pop() ?? null
|
||||
}
|
||||
|
||||
takeFollowUp(): QueuedPrompt | null {
|
||||
this.armed = false
|
||||
return this.prompts.shift() ?? null
|
||||
}
|
||||
|
||||
snapshot(): readonly QueuedPrompt[] {
|
||||
return this.prompts
|
||||
}
|
||||
|
||||
restore(): QueuedPrompt[] {
|
||||
const prompts = this.prompts
|
||||
this.prompts = []
|
||||
this.armed = false
|
||||
return prompts
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.prompts = []
|
||||
this.armed = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user