feat(ui): Delete session button in Chat tab
Adds a Delete button to the Chat tab with confirmation modal. Features: - Delete button next to Stop/New session (disabled during generation) - Hidden for main session (cannot delete main) - Confirmation modal with session name - Enter key to confirm, Escape to cancel - After deletion: switches to main session and refreshes chat - Archives transcript when deleting (same as Sessions tab) Changes: - ui/src/ui/views/chat.ts: Add delete props, modal overlay, delete button - ui/src/ui/app.ts: Add chatDeleteConfirm state - ui/src/ui/app-render.ts: Wire up delete handlers, hide for main, switch after delete - ui/src/styles/components.css: Styles for confirmation modal
This commit is contained in:
parent
6372242da7
commit
0831ee3865
@ -1484,3 +1484,49 @@
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Delete session confirmation modal */
|
||||||
|
.chat-delete-overlay {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 100;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-delete-card {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px 24px;
|
||||||
|
max-width: 360px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-delete-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-delete-sub {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-bottom: 16px;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-delete-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-delete-hint {
|
||||||
|
margin-top: 12px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|||||||
@ -497,6 +497,28 @@ export function renderApp(state: AppViewState) {
|
|||||||
onSplitRatioChange: (ratio: number) => state.handleSplitRatioChange(ratio),
|
onSplitRatioChange: (ratio: number) => state.handleSplitRatioChange(ratio),
|
||||||
assistantName: state.assistantName,
|
assistantName: state.assistantName,
|
||||||
assistantAvatar: state.assistantAvatar,
|
assistantAvatar: state.assistantAvatar,
|
||||||
|
// Delete session (hidden for main session)
|
||||||
|
showDeleteConfirm: state.chatDeleteConfirm,
|
||||||
|
onDeleteClick:
|
||||||
|
state.sessionKey === "main" ||
|
||||||
|
parseAgentSessionKey(state.sessionKey)?.rest === "main"
|
||||||
|
? undefined
|
||||||
|
: () => (state.chatDeleteConfirm = true),
|
||||||
|
onDeleteConfirm: async () => {
|
||||||
|
state.chatDeleteConfirm = false;
|
||||||
|
const { deleteSession } = await import("./controllers/sessions");
|
||||||
|
await deleteSession(state as Parameters<typeof deleteSession>[0], state.sessionKey);
|
||||||
|
// Switch to main session after deletion
|
||||||
|
const mainKey = state.sessionsResult?.mainSessionKey ?? "main";
|
||||||
|
state.sessionKey = mainKey;
|
||||||
|
state.applySettings({
|
||||||
|
...state.settings,
|
||||||
|
sessionKey: mainKey,
|
||||||
|
lastActiveSessionKey: mainKey,
|
||||||
|
});
|
||||||
|
void loadChatHistory(state);
|
||||||
|
},
|
||||||
|
onDeleteCancel: () => (state.chatDeleteConfirm = false),
|
||||||
})
|
})
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
|
|||||||
@ -130,6 +130,7 @@ export class MoltbotApp extends LitElement {
|
|||||||
@state() chatThinkingLevel: string | null = null;
|
@state() chatThinkingLevel: string | null = null;
|
||||||
@state() chatQueue: ChatQueueItem[] = [];
|
@state() chatQueue: ChatQueueItem[] = [];
|
||||||
@state() chatAttachments: ChatAttachment[] = [];
|
@state() chatAttachments: ChatAttachment[] = [];
|
||||||
|
@state() chatDeleteConfirm = false;
|
||||||
// Sidebar state for tool output viewing
|
// Sidebar state for tool output viewing
|
||||||
@state() sidebarOpen = false;
|
@state() sidebarOpen = false;
|
||||||
@state() sidebarContent: string | null = null;
|
@state() sidebarContent: string | null = null;
|
||||||
|
|||||||
@ -68,6 +68,11 @@ export type ChatProps = {
|
|||||||
onCloseSidebar?: () => void;
|
onCloseSidebar?: () => void;
|
||||||
onSplitRatioChange?: (ratio: number) => void;
|
onSplitRatioChange?: (ratio: number) => void;
|
||||||
onChatScroll?: (event: Event) => void;
|
onChatScroll?: (event: Event) => void;
|
||||||
|
// Delete session
|
||||||
|
showDeleteConfirm?: boolean;
|
||||||
|
onDeleteClick?: () => void;
|
||||||
|
onDeleteConfirm?: () => void;
|
||||||
|
onDeleteCancel?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const COMPACTION_TOAST_DURATION_MS = 5000;
|
const COMPACTION_TOAST_DURATION_MS = 5000;
|
||||||
@ -240,7 +245,44 @@ export function renderChat(props: ChatProps) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<section class="card chat">
|
<section
|
||||||
|
class="card chat"
|
||||||
|
tabindex="-1"
|
||||||
|
@keydown=${(e: KeyboardEvent) => {
|
||||||
|
// Escape to cancel delete confirmation
|
||||||
|
if (e.key === "Escape" && props.showDeleteConfirm && props.onDeleteCancel) {
|
||||||
|
e.preventDefault();
|
||||||
|
props.onDeleteCancel();
|
||||||
|
}
|
||||||
|
// Enter to confirm delete
|
||||||
|
if (e.key === "Enter" && props.showDeleteConfirm && props.onDeleteConfirm) {
|
||||||
|
e.preventDefault();
|
||||||
|
props.onDeleteConfirm();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
${props.showDeleteConfirm
|
||||||
|
? html`
|
||||||
|
<div class="chat-delete-overlay" role="dialog" aria-modal="true">
|
||||||
|
<div class="chat-delete-card">
|
||||||
|
<div class="chat-delete-title">Delete this session?</div>
|
||||||
|
<div class="chat-delete-sub">
|
||||||
|
This will permanently delete the session "${props.sessionKey}".
|
||||||
|
</div>
|
||||||
|
<div class="chat-delete-actions">
|
||||||
|
<button class="btn" @click=${props.onDeleteCancel} autofocus>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button class="btn danger" @click=${props.onDeleteConfirm}>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="chat-delete-hint">Press Enter to delete, Escape to cancel</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
|
|
||||||
${props.disabledReason
|
${props.disabledReason
|
||||||
? html`<div class="callout">${props.disabledReason}</div>`
|
? html`<div class="callout">${props.disabledReason}</div>`
|
||||||
: nothing}
|
: nothing}
|
||||||
@ -361,6 +403,18 @@ export function renderChat(props: ChatProps) {
|
|||||||
>
|
>
|
||||||
${canAbort ? "Stop" : "New session"}
|
${canAbort ? "Stop" : "New session"}
|
||||||
</button>
|
</button>
|
||||||
|
${props.onDeleteClick
|
||||||
|
? html`
|
||||||
|
<button
|
||||||
|
class="btn danger"
|
||||||
|
?disabled=${!props.connected || isBusy}
|
||||||
|
@click=${props.onDeleteClick}
|
||||||
|
title="Delete this session"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
<button
|
<button
|
||||||
class="btn primary"
|
class="btn primary"
|
||||||
?disabled=${!props.connected}
|
?disabled=${!props.connected}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user