fix(tui): restore prompt after undo (#35987)
This commit is contained in:
@@ -430,29 +430,34 @@ export function Session() {
|
|||||||
category: "Session",
|
category: "Session",
|
||||||
slash: { name: "undo" },
|
slash: { name: "undo" },
|
||||||
run: () => {
|
run: () => {
|
||||||
void (async () => {
|
const boundary = session()?.revert?.messageID
|
||||||
const boundary = session()?.revert?.messageID
|
const message = messages().findLast(
|
||||||
const list = messages()
|
(message): message is SessionMessageUser =>
|
||||||
let target: string | undefined
|
message.type === "user" && !!message.text.trim() && (!boundary || message.id < boundary),
|
||||||
for (let i = list.length - 1; i >= 0; i--) {
|
)
|
||||||
const message = list[i]
|
if (!message) {
|
||||||
if (message.type !== "user" || !message.text.trim()) continue
|
toast.show({ message: "Nothing to undo", variant: "error", duration: 3000 })
|
||||||
if (boundary && message.id >= boundary) continue
|
|
||||||
target = message.id
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (!target) {
|
|
||||||
toast.show({ message: "Nothing to undo", variant: "error", duration: 3000 })
|
|
||||||
dialog.clear()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const error = await sdk.api.session.revert.stage({ sessionID: route.sessionID, messageID: target }).then(
|
|
||||||
() => undefined,
|
|
||||||
(error) => error,
|
|
||||||
)
|
|
||||||
if (error) toast.show({ message: errorMessage(error), variant: "error", duration: 5000 })
|
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
})()
|
return
|
||||||
|
}
|
||||||
|
void sdk.api.session.revert
|
||||||
|
.stage({ sessionID: route.sessionID, messageID: message.id })
|
||||||
|
.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
||||||
|
prompt?.set({
|
||||||
|
text: message.text,
|
||||||
|
files: message.files?.map((file) => ({
|
||||||
|
uri: file.source.type === "uri" ? file.source.uri : `data:${file.mime};base64,${file.data}`,
|
||||||
|
name: file.name,
|
||||||
|
description: file.description,
|
||||||
|
mention: file.mention ? { ...file.mention } : undefined,
|
||||||
|
})),
|
||||||
|
agents: message.agents?.map((agent) => ({
|
||||||
|
name: agent.name,
|
||||||
|
mention: agent.mention ? { ...agent.mention } : undefined,
|
||||||
|
})),
|
||||||
|
pasted: [],
|
||||||
|
})
|
||||||
|
dialog.clear()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user