improve prompt submission history handling

This commit is contained in:
Shantur Rathore
2025-11-23 14:41:49 +00:00
parent 002efad9ad
commit 011533b3c4

View File

@@ -25,6 +25,7 @@ interface PromptInputProps {
export default function PromptInput(props: PromptInputProps) { export default function PromptInput(props: PromptInputProps) {
const [prompt, setPromptInternal] = createSignal("") const [prompt, setPromptInternal] = createSignal("")
const [history, setHistory] = createSignal<string[]>([]) const [history, setHistory] = createSignal<string[]>([])
const HISTORY_LIMIT = 100
const [historyIndex, setHistoryIndex] = createSignal(-1) const [historyIndex, setHistoryIndex] = createSignal(-1)
const [historyDraft, setHistoryDraft] = createSignal<string | null>(null) const [historyDraft, setHistoryDraft] = createSignal<string | null>(null)
const [, setIsFocused] = createSignal(false) const [, setIsFocused] = createSignal(false)
@@ -499,11 +500,27 @@ export default function PromptInput(props: PromptInputProps) {
async function handleSend() { async function handleSend() {
const text = prompt().trim() const text = prompt().trim()
const currentAttachments = attachments() const currentAttachments = attachments()
if (props.disabled || !text) return if (props.disabled || (!text && currentAttachments.length === 0)) return
const resolvedPrompt = resolvePastedPlaceholders(text, currentAttachments) const resolvedPrompt = resolvePastedPlaceholders(text, currentAttachments)
const isShellMode = mode() === "shell" const isShellMode = mode() === "shell"
const refreshHistory = async () => {
try {
await addToHistory(props.instanceFolder, resolvedPrompt)
setHistory((prev) => {
const next = [resolvedPrompt, ...prev]
if (next.length > HISTORY_LIMIT) {
next.length = HISTORY_LIMIT
}
return next
})
setHistoryIndex(-1)
} catch (historyError) {
console.error("Failed to update prompt history:", historyError)
}
}
clearPrompt() clearPrompt()
clearAttachments(props.instanceId, props.sessionId) clearAttachments(props.instanceId, props.sessionId)
setIgnoredAtPositions(new Set<number>()) setIgnoredAtPositions(new Set<number>())
@@ -512,10 +529,6 @@ export default function PromptInput(props: PromptInputProps) {
setHistoryDraft(null) setHistoryDraft(null)
try { try {
await addToHistory(props.instanceFolder, resolvedPrompt)
const updated = await getHistory(props.instanceFolder)
setHistory(updated)
setHistoryIndex(-1)
if (isShellMode) { if (isShellMode) {
if (props.onRunShell) { if (props.onRunShell) {
await props.onRunShell(resolvedPrompt) await props.onRunShell(resolvedPrompt)
@@ -523,8 +536,9 @@ export default function PromptInput(props: PromptInputProps) {
await props.onSend(resolvedPrompt, []) await props.onSend(resolvedPrompt, [])
} }
} else { } else {
await props.onSend(text, currentAttachments) await props.onSend(resolvedPrompt, currentAttachments)
} }
void refreshHistory()
} catch (error) { } catch (error) {
console.error("Failed to send message:", error) console.error("Failed to send message:", error)
showAlertDialog("Failed to send message", { showAlertDialog("Failed to send message", {