feat(client): add lazy-loaded AI Assistant drawer across 5 surfaces and Settings AI/Backup panels

This commit is contained in:
tyuXX 2026-11-27 14:31:43 +00:00
parent 01aae91982
commit 6dcfa81925
8 changed files with 859 additions and 22 deletions

View file

@ -3,7 +3,7 @@ import type { FitAddon } from '@xterm/addon-fit';
import type { ServerWsFrame } from '../../../shared/ws-protocol.js';
import { apiFetch } from '../api.js';
import { confirmDialog } from '../dialogs.js';
import { el, extractErrorMessage, fmtTime, type ClientState, type ServerEntry } from '../state.js';
import { el, extractErrorMessage, fmtTime, isAiEnabled, type ClientState, type ServerEntry } from '../state.js';
import type { MultiplexWsClient } from '../ws-client.js';
import {
clearTerminalComposition,
@ -349,6 +349,39 @@ export async function renderTerminalView(
const fontPlusBtn = el('button', { type: 'button', class: 'btn btn-sm' }, 'A+');
const fitBtn = el('button', { type: 'button', class: 'btn btn-sm' }, 'Fit');
const snippetsBtn = el('button', { type: 'button', class: 'btn btn-sm' }, 'Snippets');
const aiTermBtn = isAiEnabled(state)
? el('button', { type: 'button', class: 'btn btn-sm' }, '[AI Helper]')
: null;
if (aiTermBtn) {
aiTermBtn.addEventListener('click', async () => {
let scrollbackTail = '';
try {
const res = await fetch(
`/api/terminal/sessions/${encodeURIComponent(current.sessionId)}/export?format=plain`,
{ credentials: 'same-origin' },
);
if (res.ok) {
scrollbackTail = (await res.text()).slice(-4000);
}
} catch {
// Ignore export errors
}
const { openAiAssistantDrawer } = await import('./ai-drawer.js');
await openAiAssistantDrawer({
state,
wsClient,
surface: 'snippets',
title: `AI Terminal Helper (${current.serverId})`,
contextText: scrollbackTail,
serverId: current.serverId,
defaultDraftKind: 'snippet',
onInsertTerminalText: (cmd) => {
sendPtyInput(cmd.replace(/[\r\n]+/g, ' '));
term?.focus();
},
});
});
}
const closeTabBtn = el(
'button',
{ type: 'button', class: 'btn btn-sm btn-danger mutating-action' },
@ -457,7 +490,7 @@ export async function renderTerminalView(
{ class: 'mono muted' },
`${current.title} | ${current.cols}x${current.rows} | opened ${fmtTime(current.createdAt)}`,
),
el('div', { class: 'row' }, fontMinusBtn, fontPlusBtn, fitBtn, snippetsBtn, exportPlainBtn, exportAnsiBtn, closeTabBtn),
el('div', { class: 'row' }, fontMinusBtn, fontPlusBtn, fitBtn, snippetsBtn, ...(aiTermBtn ? [aiTermBtn] : []), exportPlainBtn, exportAnsiBtn, closeTabBtn),
),
el('div', { class: 'term-shell' }, termContainer, touchBar),
),