feat(tui): wire up undo/redo and revert for V2 sessions (#34263)
This commit is contained in:
parent
cd942d0669
commit
d1d7ebc2c6
20 changed files with 478 additions and 87 deletions
|
|
@ -13,6 +13,7 @@ import { useLocal } from "../context/local"
|
|||
import { createDebouncedSignal } from "../util/signal"
|
||||
import { useToast } from "../ui/toast"
|
||||
import { useCommandShortcut } from "../keymap"
|
||||
import { DialogSessionRename } from "./dialog-session-rename"
|
||||
import { Spinner } from "./spinner"
|
||||
|
||||
export function DialogSessionList() {
|
||||
|
|
@ -121,7 +122,8 @@ export function DialogSessionList() {
|
|||
{
|
||||
command: "session.rename",
|
||||
title: "rename",
|
||||
onTrigger: () => unavailable("Renaming"),
|
||||
onTrigger: (option: { value: string }) =>
|
||||
DialogSessionRename.show(dialog, option.value, data.session.get(option.value)?.title),
|
||||
},
|
||||
]}
|
||||
footerHints={quickSwitchFooterHints()}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,33 @@
|
|||
import { DialogPrompt } from "../ui/dialog-prompt"
|
||||
import { useDialog } from "../ui/dialog"
|
||||
import { useSync } from "../context/sync"
|
||||
import { createMemo } from "solid-js"
|
||||
import { type DialogContext, useDialog } from "../ui/dialog"
|
||||
import { useSDK } from "../context/sdk"
|
||||
import { useToast } from "../ui/toast"
|
||||
import { errorMessage } from "../util/error"
|
||||
|
||||
interface DialogSessionRenameProps {
|
||||
session: string
|
||||
}
|
||||
|
||||
export function DialogSessionRename(props: DialogSessionRenameProps) {
|
||||
export function DialogSessionRename(props: { sessionID: string; currentTitle?: string }) {
|
||||
const dialog = useDialog()
|
||||
const sync = useSync()
|
||||
const sdk = useSDK()
|
||||
const session = createMemo(() => sync.session.get(props.session))
|
||||
const toast = useToast()
|
||||
|
||||
return (
|
||||
<DialogPrompt
|
||||
title="Rename Session"
|
||||
value={session()?.title}
|
||||
title="Rename session"
|
||||
placeholder="Session title"
|
||||
value={props.currentTitle}
|
||||
onConfirm={(value) => {
|
||||
void sdk.client.session.update({
|
||||
sessionID: props.session,
|
||||
title: value,
|
||||
})
|
||||
dialog.clear()
|
||||
const title = value.trim()
|
||||
if (!title) return
|
||||
void sdk.client.v2.session
|
||||
.rename({ sessionID: props.sessionID, title }, { throwOnError: true })
|
||||
.then(() => dialog.clear())
|
||||
.catch((error) =>
|
||||
toast.show({ message: `Failed to rename session: ${errorMessage(error)}`, variant: "error", duration: 5000 }),
|
||||
)
|
||||
}}
|
||||
onCancel={() => dialog.clear()}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
DialogSessionRename.show = (dialog: DialogContext, sessionID: string, currentTitle?: string) =>
|
||||
dialog.replace(() => <DialogSessionRename sessionID={sessionID} currentTitle={currentTitle} />)
|
||||
|
|
|
|||
|
|
@ -1104,6 +1104,13 @@ export function Prompt(props: PromptProps) {
|
|||
{ throwOnError: true },
|
||||
)
|
||||
}
|
||||
if (session?.revert) {
|
||||
const revertResult = await sdk.client.v2.session.revert.commit({ sessionID })
|
||||
if (revertResult.error) {
|
||||
toast.show({ title: "Failed to commit revert", message: errorMessage(revertResult.error), variant: "error" })
|
||||
return false
|
||||
}
|
||||
}
|
||||
const result = await sdk.client.v2.session.prompt({
|
||||
sessionID,
|
||||
prompt: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue