mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-26 01:01:40 +00:00
20 lines
597 B
TypeScript
20 lines
597 B
TypeScript
import { useRef, useState } from 'react'
|
|
|
|
import * as inputHistory from '../lib/history.js'
|
|
|
|
export function useInputHistory() {
|
|
const historyRef = useRef<string[]>(inputHistory.load())
|
|
const [historyIdx, setHistoryIdx] = useState<number | null>(null)
|
|
const historyDraftRef = useRef('')
|
|
|
|
const pushHistory = (text: string) => {
|
|
const trimmed = text.trim()
|
|
|
|
if (trimmed && historyRef.current.at(-1) !== trimmed) {
|
|
historyRef.current.push(trimmed)
|
|
inputHistory.append(trimmed)
|
|
}
|
|
}
|
|
|
|
return { historyRef, historyIdx, setHistoryIdx, historyDraftRef, pushHistory }
|
|
}
|