fix(tui): restore clicked reverted prompt
This commit is contained in:
committed by
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
parent
f8f8cc9546
commit
7157bfb8d5
@@ -6,12 +6,15 @@ import { useToast } from "../../ui/toast"
|
|||||||
import { useSDK } from "../../context/sdk"
|
import { useSDK } from "../../context/sdk"
|
||||||
import { errorMessage } from "../../util/error"
|
import { errorMessage } from "../../util/error"
|
||||||
import { DialogFork } from "./dialog-fork"
|
import { DialogFork } from "./dialog-fork"
|
||||||
|
import { usePromptRef } from "../../context/prompt"
|
||||||
|
import { revertedPrompt } from "../../util/revert-prompt"
|
||||||
|
|
||||||
export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
||||||
const data = useData()
|
const data = useData()
|
||||||
const clipboard = useClipboard()
|
const clipboard = useClipboard()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
|
const promptRef = usePromptRef()
|
||||||
const message = createMemo(() => data.session.message.get(props.sessionID, props.messageID))
|
const message = createMemo(() => data.session.message.get(props.sessionID, props.messageID))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -23,9 +26,18 @@ export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
|||||||
value: "session.revert",
|
value: "session.revert",
|
||||||
description: "undo messages and file changes",
|
description: "undo messages and file changes",
|
||||||
onSelect: async (dialog) => {
|
onSelect: async (dialog) => {
|
||||||
await sdk.api.session
|
const error = await sdk.api.session.revert
|
||||||
.revert.stage({ sessionID: props.sessionID, messageID: props.messageID })
|
.stage({ sessionID: props.sessionID, messageID: props.messageID })
|
||||||
.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
.then(
|
||||||
|
() => undefined,
|
||||||
|
(error) => error,
|
||||||
|
)
|
||||||
|
if (error) {
|
||||||
|
toast.show({ message: errorMessage(error), variant: "error", duration: 5000 })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const value = message()
|
||||||
|
if (value?.type === "user") promptRef.current?.set(revertedPrompt(value))
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ import { usePathFormatter } from "../../context/path-format"
|
|||||||
import { LocationProvider } from "../../context/location"
|
import { LocationProvider } from "../../context/location"
|
||||||
import { createSessionRows, resolvePart, type PartRef, type SessionRow } from "./rows"
|
import { createSessionRows, resolvePart, type PartRef, type SessionRow } from "./rows"
|
||||||
import { switchLabel } from "../../util/model"
|
import { switchLabel } from "../../util/model"
|
||||||
|
import { revertedPrompt } from "../../util/revert-prompt"
|
||||||
|
|
||||||
addDefaultParsers(parsers.parsers)
|
addDefaultParsers(parsers.parsers)
|
||||||
|
|
||||||
@@ -424,20 +425,7 @@ export function Session() {
|
|||||||
void sdk.api.session.revert
|
void sdk.api.session.revert
|
||||||
.stage({ sessionID: route.sessionID, messageID: message.id })
|
.stage({ sessionID: route.sessionID, messageID: message.id })
|
||||||
.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
||||||
prompt?.set({
|
prompt?.set(revertedPrompt(message))
|
||||||
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()
|
dialog.clear()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import type { SessionMessageUser } from "@opencode-ai/client"
|
||||||
|
import type { PromptInfo } from "../prompt/history"
|
||||||
|
|
||||||
|
export function revertedPrompt(message: SessionMessageUser): PromptInfo {
|
||||||
|
return {
|
||||||
|
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: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import type { SessionMessageUser } from "@opencode-ai/client"
|
||||||
|
import { revertedPrompt } from "../../src/util/revert-prompt"
|
||||||
|
|
||||||
|
describe("reverted prompt", () => {
|
||||||
|
test("restores message text and references", () => {
|
||||||
|
const message = {
|
||||||
|
id: "message-1",
|
||||||
|
type: "user",
|
||||||
|
text: "Fix @test.ts with @review",
|
||||||
|
time: { created: 1 },
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
mime: "text/typescript",
|
||||||
|
name: "test.ts",
|
||||||
|
description: "test file",
|
||||||
|
data: "",
|
||||||
|
source: { type: "uri", uri: "file:///repo/test.ts" },
|
||||||
|
mention: { start: 4, end: 12, text: "@test.ts" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
agents: [{ name: "review", mention: { start: 18, end: 25, text: "@review" } }],
|
||||||
|
} satisfies SessionMessageUser
|
||||||
|
|
||||||
|
expect(revertedPrompt(message)).toEqual({
|
||||||
|
text: "Fix @test.ts with @review",
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
uri: "file:///repo/test.ts",
|
||||||
|
name: "test.ts",
|
||||||
|
description: "test file",
|
||||||
|
mention: { start: 4, end: 12, text: "@test.ts" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
agents: [{ name: "review", mention: { start: 18, end: 25, text: "@review" } }],
|
||||||
|
pasted: [],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user