mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-13 03:52:00 +00:00
fix(tui): stabilize live todo progress
This commit is contained in:
parent
1566f1eecc
commit
f5552f92e2
14 changed files with 256 additions and 86 deletions
34
ui-tui/src/lib/liveProgress.ts
Normal file
34
ui-tui/src/lib/liveProgress.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import type { Msg, TodoItem } from '../types.js'
|
||||
|
||||
export const isTodoDone = (todos: readonly TodoItem[]) =>
|
||||
todos.length > 0 && todos.every(todo => todo.status === 'completed' || todo.status === 'cancelled')
|
||||
|
||||
export const isToolShelfMessage = (msg: Msg | undefined) =>
|
||||
Boolean(msg?.kind === 'trail' && !msg.text && !msg.thinking?.trim() && msg.tools?.length)
|
||||
|
||||
const canHoldToolShelf = (msg: Msg | undefined) =>
|
||||
Boolean(msg?.kind === 'trail' && !msg.text && (msg.thinking?.trim() || msg.tools?.length))
|
||||
|
||||
export const appendToolShelfMessage = (prev: readonly Msg[], msg: Msg): Msg[] => {
|
||||
if (!isToolShelfMessage(msg)) {
|
||||
return [...prev, msg]
|
||||
}
|
||||
|
||||
for (let index = prev.length - 1; index >= 0; index--) {
|
||||
const candidate = prev[index]
|
||||
|
||||
if (canHoldToolShelf(candidate)) {
|
||||
const next = [...prev]
|
||||
|
||||
next[index] = { ...candidate!, tools: [...(candidate!.tools ?? []), ...(msg.tools ?? [])] }
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
if (candidate?.kind !== 'trail' || candidate.text) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return [...prev, msg]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue