UI: add expand-to-canvas button and session navigation from sessions/cron views
This commit is contained in:
parent
52662d39d6
commit
95e20e8a35
@ -194,10 +194,31 @@ img.chat-avatar {
|
||||
padding-right: 36px;
|
||||
}
|
||||
|
||||
.chat-copy-btn {
|
||||
.chat-bubble-actions {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 8px;
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 120ms ease-out;
|
||||
}
|
||||
|
||||
.chat-bubble:hover .chat-bubble-actions {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
@media (hover: none) {
|
||||
.chat-bubble-actions {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-copy-btn,
|
||||
.chat-expand-btn {
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
color: var(--muted);
|
||||
@ -206,11 +227,7 @@ img.chat-avatar {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition:
|
||||
opacity 120ms ease-out,
|
||||
background 120ms ease-out;
|
||||
transition: background 120ms ease-out;
|
||||
}
|
||||
|
||||
.chat-copy-btn__icon {
|
||||
@ -250,12 +267,8 @@ img.chat-avatar {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.chat-bubble:hover .chat-copy-btn {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.chat-copy-btn:hover {
|
||||
.chat-copy-btn:hover,
|
||||
.chat-expand-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
@ -265,33 +278,37 @@ img.chat-avatar {
|
||||
}
|
||||
|
||||
.chat-copy-btn[data-error="1"] {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
border-color: var(--danger-subtle);
|
||||
background: var(--danger-subtle);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.chat-copy-btn[data-copied="1"] {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
border-color: var(--ok-subtle);
|
||||
background: var(--ok-subtle);
|
||||
color: var(--ok);
|
||||
}
|
||||
|
||||
.chat-copy-btn:focus-visible {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
.chat-copy-btn:focus-visible,
|
||||
.chat-expand-btn:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
@media (hover: none) {
|
||||
.chat-copy-btn {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.chat-expand-btn__icon {
|
||||
display: inline-flex;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.chat-expand-btn__icon svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
stroke: currentColor;
|
||||
fill: none;
|
||||
stroke-width: 1.5px;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
/* Light mode: restore borders */
|
||||
|
||||
@ -1312,6 +1312,96 @@
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
/* Code block wrapper chrome (generated by markdown renderer) */
|
||||
|
||||
.code-block-wrapper {
|
||||
position: relative;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
|
||||
.code-block-wrapper pre {
|
||||
margin: 0;
|
||||
border-radius: 0 0 6px 6px;
|
||||
}
|
||||
|
||||
.code-block-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 4px 8px 4px 12px;
|
||||
background: rgba(0, 0, 0, 0.25);
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
:root[data-theme-mode="light"] .code-block-header {
|
||||
background: rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.code-block-lang {
|
||||
color: var(--muted);
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
text-transform: lowercase;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.code-block-copy {
|
||||
appearance: none;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font-family: var(--font-body);
|
||||
cursor: pointer;
|
||||
padding: 2px 6px;
|
||||
border-radius: var(--radius-sm);
|
||||
transition:
|
||||
color 150ms ease,
|
||||
background 150ms ease;
|
||||
}
|
||||
|
||||
.code-block-copy:hover {
|
||||
color: var(--text);
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
:root[data-theme-mode="light"] .code-block-copy:hover {
|
||||
background: rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.code-block-copy__done {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.code-block-copy.copied .code-block-copy__idle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.code-block-copy.copied .code-block-copy__done {
|
||||
display: inline;
|
||||
color: var(--success, #22c55e);
|
||||
}
|
||||
|
||||
.json-collapse {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
|
||||
.json-collapse summary {
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
padding: 4px 8px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.json-collapse summary:hover {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
/* ===========================================
|
||||
Lists
|
||||
=========================================== */
|
||||
|
||||
@ -487,7 +487,7 @@ export function renderChatMobileToggle(state: AppViewState) {
|
||||
`;
|
||||
}
|
||||
|
||||
function switchChatSession(state: AppViewState, nextSessionKey: string) {
|
||||
export function switchChatSession(state: AppViewState, nextSessionKey: string) {
|
||||
state.sessionKey = nextSessionKey;
|
||||
state.chatMessage = "";
|
||||
state.chatStream = null;
|
||||
|
||||
@ -14,6 +14,7 @@ import {
|
||||
renderTab,
|
||||
renderSidebarConnectionStatus,
|
||||
renderTopbarThemeModeToggle,
|
||||
switchChatSession,
|
||||
} from "./app-render.helpers.ts";
|
||||
import type { AppViewState } from "./app-view-state.ts";
|
||||
import { loadAgentFileContent, loadAgentFiles, saveAgentFile } from "./controllers/agent-files.ts";
|
||||
@ -765,6 +766,10 @@ export function renderApp(state: AppViewState) {
|
||||
onRefresh: () => loadSessions(state),
|
||||
onPatch: (key, patch) => patchSession(state, key, patch),
|
||||
onDelete: (key) => deleteSessionAndRefresh(state, key),
|
||||
onNavigateToChat: (sessionKey) => {
|
||||
switchChatSession(state, sessionKey);
|
||||
state.setTab("chat" as import("./navigation.ts").Tab);
|
||||
},
|
||||
}),
|
||||
)
|
||||
: nothing
|
||||
@ -865,6 +870,10 @@ export function renderApp(state: AppViewState) {
|
||||
}
|
||||
await loadCronRuns(state, state.cronRunsJobId);
|
||||
},
|
||||
onNavigateToChat: (sessionKey) => {
|
||||
switchChatSession(state, sessionKey);
|
||||
state.setTab("chat" as import("./navigation.ts").Tab);
|
||||
},
|
||||
}),
|
||||
)
|
||||
: nothing
|
||||
@ -1432,10 +1441,7 @@ export function renderApp(state: AppViewState) {
|
||||
state.setTab("agents" as import("./navigation.ts").Tab);
|
||||
},
|
||||
onSessionSelect: (key: string) => {
|
||||
state.setSessionKey(key);
|
||||
state.chatMessages = [];
|
||||
void loadChatHistory(state);
|
||||
void state.loadAssistantIdentity();
|
||||
switchChatSession(state, key);
|
||||
},
|
||||
showNewMessages: state.chatNewMessagesBelow && !state.chatManualRefreshInFlight,
|
||||
onScrollToBottom: () => state.scrollToBottom(),
|
||||
|
||||
@ -357,7 +357,6 @@ export type AppViewState = {
|
||||
handleDebugCall: () => Promise<void>;
|
||||
handleRunUpdate: () => Promise<void>;
|
||||
setPassword: (next: string) => void;
|
||||
setSessionKey: (next: string) => void;
|
||||
setChatMessage: (next: string) => void;
|
||||
handleSendChat: (messageOverride?: string, opts?: { restoreDraft?: boolean }) => Promise<void>;
|
||||
handleAbortChat: () => Promise<void>;
|
||||
|
||||
@ -620,6 +620,20 @@ function jsonSummaryLabel(parsed: unknown): string {
|
||||
return "JSON";
|
||||
}
|
||||
|
||||
function renderExpandButton(markdown: string, onOpenSidebar: (content: string) => void) {
|
||||
return html`
|
||||
<button
|
||||
class="chat-expand-btn"
|
||||
type="button"
|
||||
title="Open in canvas"
|
||||
aria-label="Open in canvas"
|
||||
@click=${() => onOpenSidebar(markdown)}
|
||||
>
|
||||
<span class="chat-expand-btn__icon" aria-hidden="true">${icons.panelRightOpen}</span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
function renderGroupedMessage(
|
||||
message: unknown,
|
||||
opts: { isStreaming: boolean; showReasoning: boolean; showToolCalls?: boolean },
|
||||
@ -647,6 +661,7 @@ function renderGroupedMessage(
|
||||
const reasoningMarkdown = extractedThinking ? formatReasoningMarkdown(extractedThinking) : null;
|
||||
const markdown = markdownBase;
|
||||
const canCopyMarkdown = role === "assistant" && Boolean(markdown?.trim());
|
||||
const canExpand = Boolean(onOpenSidebar && markdown?.trim());
|
||||
|
||||
// Detect pure-JSON messages and render as collapsible block
|
||||
const jsonResult = markdown && !opts.isStreaming ? detectJson(markdown) : null;
|
||||
@ -674,9 +689,18 @@ function renderGroupedMessage(
|
||||
const toolPreview =
|
||||
markdown && !toolSummaryLabel ? markdown.trim().replace(/\s+/g, " ").slice(0, 120) : "";
|
||||
|
||||
const hasActions = canCopyMarkdown || canExpand;
|
||||
|
||||
return html`
|
||||
<div class="${bubbleClasses}">
|
||||
${canCopyMarkdown ? html`<div class="chat-bubble-actions">${renderCopyAsMarkdownButton(markdown!)}</div>` : nothing}
|
||||
${
|
||||
hasActions
|
||||
? html`<div class="chat-bubble-actions">
|
||||
${canExpand ? renderExpandButton(markdown!, onOpenSidebar!) : nothing}
|
||||
${canCopyMarkdown ? renderCopyAsMarkdownButton(markdown!) : nothing}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
isToolMessage
|
||||
? html`
|
||||
|
||||
@ -441,6 +441,13 @@ export const icons = {
|
||||
<path d="M7 4v16" />
|
||||
</svg>
|
||||
`,
|
||||
panelRightOpen: html`
|
||||
<svg viewBox="0 0 24 24">
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
<path d="M15 3v18" stroke-linecap="round" />
|
||||
<path d="M10 10l-3 2 3 2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
`,
|
||||
} as const;
|
||||
|
||||
export type IconName = keyof typeof icons;
|
||||
|
||||
@ -91,6 +91,7 @@ export type CronProps = {
|
||||
cronRunsQuery?: string;
|
||||
cronRunsSortDir?: CronSortDir;
|
||||
}) => void | Promise<void>;
|
||||
onNavigateToChat?: (sessionKey: string) => void;
|
||||
};
|
||||
|
||||
function getRunStatusOptions(): Array<{ value: CronRunsStatusValue; label: string }> {
|
||||
|
||||
@ -43,6 +43,7 @@ export type SessionsProps = {
|
||||
},
|
||||
) => void;
|
||||
onDelete: (key: string) => void;
|
||||
onNavigateToChat?: (sessionKey: string) => void;
|
||||
};
|
||||
|
||||
const THINK_LEVELS = ["", "off", "minimal", "low", "medium", "high", "xhigh"] as const;
|
||||
@ -337,6 +338,7 @@ export function renderSessions(props: SessionsProps) {
|
||||
props.onActionsOpenChange,
|
||||
props.actionsOpenKey,
|
||||
props.loading,
|
||||
props.onNavigateToChat,
|
||||
),
|
||||
)
|
||||
}
|
||||
@ -391,6 +393,7 @@ function renderRow(
|
||||
onActionsOpenChange: (key: string | null) => void,
|
||||
actionsOpenKey: string | null,
|
||||
disabled: boolean,
|
||||
onNavigateToChat?: (sessionKey: string) => void,
|
||||
) {
|
||||
const updated = row.updatedAt ? formatRelativeTimestamp(row.updatedAt) : "n/a";
|
||||
const rawThinking = row.thinkingLevel ?? "";
|
||||
@ -430,7 +433,30 @@ function renderRow(
|
||||
<tr>
|
||||
<td>
|
||||
<div class="mono session-key-cell">
|
||||
${canLink ? html`<a href=${chatUrl} class="session-link">${row.key}</a>` : row.key}
|
||||
${
|
||||
canLink
|
||||
? html`<a
|
||||
href=${chatUrl}
|
||||
class="session-link"
|
||||
@click=${(e: MouseEvent) => {
|
||||
if (
|
||||
e.defaultPrevented ||
|
||||
e.button !== 0 ||
|
||||
e.metaKey ||
|
||||
e.ctrlKey ||
|
||||
e.shiftKey ||
|
||||
e.altKey
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (onNavigateToChat) {
|
||||
e.preventDefault();
|
||||
onNavigateToChat(row.key);
|
||||
}
|
||||
}}
|
||||
>${row.key}</a>`
|
||||
: row.key
|
||||
}
|
||||
${
|
||||
showDisplayName
|
||||
? html`<span class="muted session-key-display-name">${displayName}</span>`
|
||||
@ -548,7 +574,23 @@ function renderRow(
|
||||
<a
|
||||
href=${chatUrl}
|
||||
style="display: block; padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--text); border-radius: var(--radius-sm);"
|
||||
@click=${() => onActionsOpenChange(null)}
|
||||
@click=${(e: MouseEvent) => {
|
||||
onActionsOpenChange(null);
|
||||
if (
|
||||
e.defaultPrevented ||
|
||||
e.button !== 0 ||
|
||||
e.metaKey ||
|
||||
e.ctrlKey ||
|
||||
e.shiftKey ||
|
||||
e.altKey
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (onNavigateToChat) {
|
||||
e.preventDefault();
|
||||
onNavigateToChat(row.key);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Open in Chat
|
||||
</a>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user