|
|
@@ -3,8 +3,13 @@ import { useSync } from "@tui/context/sync"
|
|
|
import { DialogSelect } from "@tui/ui/dialog-select"
|
|
|
import { useSDK } from "@tui/context/sdk"
|
|
|
import { useRoute } from "@tui/context/route"
|
|
|
+import type { PromptInfo } from "@tui/component/prompt/history"
|
|
|
|
|
|
-export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
|
|
+export function DialogMessage(props: {
|
|
|
+ messageID: string
|
|
|
+ sessionID: string
|
|
|
+ setPrompt?: (prompt: PromptInfo) => void
|
|
|
+}) {
|
|
|
const sync = useSync()
|
|
|
const sdk = useSDK()
|
|
|
const message = createMemo(() => sync.data.message[props.sessionID]?.find((x) => x.id === props.messageID))
|
|
|
@@ -19,14 +24,33 @@ export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
|
|
value: "session.revert",
|
|
|
description: "undo messages and file changes",
|
|
|
onSelect: (dialog) => {
|
|
|
+ const msg = message()
|
|
|
+ if (!msg) return
|
|
|
+
|
|
|
sdk.client.session.revert({
|
|
|
path: {
|
|
|
id: props.sessionID,
|
|
|
},
|
|
|
body: {
|
|
|
- messageID: message()!.id,
|
|
|
+ messageID: msg.id,
|
|
|
},
|
|
|
})
|
|
|
+
|
|
|
+ if (props.setPrompt) {
|
|
|
+ const parts = sync.data.part[msg.id]
|
|
|
+ const promptInfo = parts.reduce(
|
|
|
+ (agg, part) => {
|
|
|
+ if (part.type === "text") {
|
|
|
+ if (!part.synthetic) agg.input += part.text
|
|
|
+ }
|
|
|
+ if (part.type === "file") agg.parts.push(part)
|
|
|
+ return agg
|
|
|
+ },
|
|
|
+ { input: "", parts: [] as PromptInfo["parts"] },
|
|
|
+ )
|
|
|
+ props.setPrompt(promptInfo)
|
|
|
+ }
|
|
|
+
|
|
|
dialog.clear()
|
|
|
},
|
|
|
},
|