mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
feat(agent): add nested agents.md support across backend and webui (#309)
* feat(agent): add nested agents.md support across backend and webui * fix(webui): update agentsmd route paths and unnest folder agentsmd route * fix(agent): flush agents.md autosave on close and address review feedback - Flush pending debounced AGENTS.md autosave on close/unmount so edits made within 750ms of navigating away are no longer silently lost - Serialize autosaves through a promise chain so an older in-flight request can never overwrite newer content on the server - Internationalize the hardcoded "Failed to save" and "Loading AGENTS.md..." strings (en + zh) - Validate that AGENTS.md is only stored on folder/root assets in AssetService, preventing bogus virtual paths for file assets - Cap updateAgentsMd content at 100k chars via Zod validation - Remove unused getAgentsMd/updateAgentsMd response DTO schemas - Drop unused teamId prop from AgentsMdEditor - Add tests: non-folder asset rejection, oversized content 400, and agent-chat workflow assetId passthrough * refactor(db): isolate AGENTS.md content in dedicated 1:1 AssetAgentMd table * style(webui): unify top bar button hover styles and add wand icon to agentsmd button * style(webui): update agentsmd button state colors and remove presence dot * fix(webui): fix close button overflow and stabilize debounced autosave in agentsmd editor * fix(webui): update debounce to 1s and await pending save before closing agentsmd editor * feat(webui): add terminal AGENTS.md breadcrumb on agentsmd editor page * fix(webui): use ScrollArea for markdown editor scrolling
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
.shumai-editor-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
border: 1px solid var(--border, #e2e8f0);
|
||||
border-radius: 8px;
|
||||
background-color: var(--background, #ffffff);
|
||||
@@ -23,7 +25,7 @@
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.shumai-editor-toolbar button {
|
||||
.shumai-editor-toolbar-left button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -38,17 +40,17 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.shumai-editor-toolbar button:hover:not(:disabled) {
|
||||
.shumai-editor-toolbar-left button:hover:not(:disabled) {
|
||||
background-color: var(--accent, #e2e8f0);
|
||||
color: var(--accent-foreground, #0f172a);
|
||||
}
|
||||
|
||||
.shumai-editor-toolbar button:disabled {
|
||||
.shumai-editor-toolbar-left button:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.shumai-editor-toolbar button.active {
|
||||
.shumai-editor-toolbar-left button.active {
|
||||
background-color: var(--primary, #0f172a);
|
||||
color: var(--primary-foreground, #ffffff);
|
||||
}
|
||||
@@ -74,14 +76,14 @@
|
||||
|
||||
.shumai-editor-content-area {
|
||||
position: relative;
|
||||
min-height: 240px;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.editor-input {
|
||||
min-height: 240px;
|
||||
min-height: 100%;
|
||||
padding: 16px;
|
||||
outline: none;
|
||||
font-size: 15px;
|
||||
|
||||
@@ -24,6 +24,7 @@ import { AutoLinkNode, LinkNode } from '@lexical/link'
|
||||
import { ToolbarPlugin } from './toolbar'
|
||||
import { editorTheme } from './theme'
|
||||
import { EDITOR_TRANSFORMERS } from './transformers'
|
||||
import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
import './markdown-editor.css'
|
||||
|
||||
function MarkdownSyncPlugin({
|
||||
@@ -90,6 +91,7 @@ export interface MarkdownEditorProps {
|
||||
autoFocus?: boolean
|
||||
className?: string
|
||||
hideToolbar?: boolean
|
||||
rightToolbarContent?: React.ReactNode
|
||||
}
|
||||
|
||||
export function MarkdownEditor({
|
||||
@@ -101,6 +103,7 @@ export function MarkdownEditor({
|
||||
autoFocus = false,
|
||||
className = '',
|
||||
hideToolbar = false,
|
||||
rightToolbarContent,
|
||||
}: MarkdownEditorProps) {
|
||||
const initialConfig: InitialConfigType = {
|
||||
namespace: 'ShumaiWysiwygMarkdownEditor',
|
||||
@@ -126,13 +129,21 @@ export function MarkdownEditor({
|
||||
return (
|
||||
<div className={`shumai-editor-wrapper ${readOnly ? 'read-only' : ''} ${className}`}>
|
||||
<LexicalComposer initialConfig={initialConfig}>
|
||||
{!readOnly && !hideToolbar && <ToolbarPlugin />}
|
||||
<div className="shumai-editor-content-area">
|
||||
<RichTextPlugin
|
||||
contentEditable={<ContentEditable className="editor-input" />}
|
||||
placeholder={<div className="editor-placeholder">{placeholder}</div>}
|
||||
ErrorBoundary={LexicalErrorBoundary}
|
||||
/>
|
||||
{!readOnly && !hideToolbar ? (
|
||||
<ToolbarPlugin rightContent={rightToolbarContent} />
|
||||
) : rightToolbarContent ? (
|
||||
<div className="shumai-editor-toolbar flex items-center justify-end px-3 py-1.5 border-b">
|
||||
{rightToolbarContent}
|
||||
</div>
|
||||
) : null}
|
||||
<ScrollArea className="shumai-editor-content-area flex-1 min-h-0 w-full">
|
||||
<div className="relative min-h-full">
|
||||
<RichTextPlugin
|
||||
contentEditable={<ContentEditable className="editor-input" />}
|
||||
placeholder={<div className="editor-placeholder">{placeholder}</div>}
|
||||
ErrorBoundary={LexicalErrorBoundary}
|
||||
/>
|
||||
</div>
|
||||
<HistoryPlugin />
|
||||
<ListPlugin />
|
||||
<CheckListPlugin />
|
||||
@@ -141,7 +152,7 @@ export function MarkdownEditor({
|
||||
<MarkdownShortcutPlugin transformers={EDITOR_TRANSFORMERS} />
|
||||
<MarkdownSyncPlugin value={value} initialContent={initialContent} onChange={onChange} />
|
||||
{autoFocus && <AutoFocusPlugin />}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</LexicalComposer>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -83,7 +83,7 @@ function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {
|
||||
}
|
||||
}
|
||||
|
||||
export function ToolbarPlugin() {
|
||||
export function ToolbarPlugin({ rightContent }: { rightContent?: React.ReactNode } = {}) {
|
||||
const [editor] = useLexicalComposerContext()
|
||||
const [canUndo, setCanUndo] = useState(false)
|
||||
const [canRedo, setCanRedo] = useState(false)
|
||||
@@ -296,194 +296,200 @@ export function ToolbarPlugin() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="shumai-editor-toolbar">
|
||||
{/* Undo / Redo */}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!canUndo}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(UNDO_COMMAND, undefined)}
|
||||
title="Undo"
|
||||
aria-label="Undo"
|
||||
>
|
||||
<Undo2 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={!canRedo}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(REDO_COMMAND, undefined)}
|
||||
title="Redo"
|
||||
aria-label="Redo"
|
||||
>
|
||||
<Redo2 className="h-4 w-4" />
|
||||
</button>
|
||||
<div className="shumai-editor-toolbar flex items-center justify-between">
|
||||
<div className="shumai-editor-toolbar-left flex items-center flex-wrap gap-1">
|
||||
{/* Undo / Redo */}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!canUndo}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(UNDO_COMMAND, undefined)}
|
||||
title="Undo"
|
||||
aria-label="Undo"
|
||||
>
|
||||
<Undo2 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={!canRedo}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(REDO_COMMAND, undefined)}
|
||||
title="Redo"
|
||||
aria-label="Redo"
|
||||
>
|
||||
<Redo2 className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
<div className="toolbar-divider" />
|
||||
<div className="toolbar-divider" />
|
||||
|
||||
{/* Block Type Dropdown */}
|
||||
<select value={blockType} onChange={handleBlockTypeChange} aria-label="Block formatting">
|
||||
<option value="paragraph">Normal</option>
|
||||
<option value="h1">Heading 1</option>
|
||||
<option value="h2">Heading 2</option>
|
||||
<option value="h3">Heading 3</option>
|
||||
<option value="bullet">Bullet List</option>
|
||||
<option value="number">Numbered List</option>
|
||||
<option value="check">Check List</option>
|
||||
<option value="quote">Quote</option>
|
||||
<option value="code">Code Block</option>
|
||||
</select>
|
||||
{/* Block Type Dropdown */}
|
||||
<select value={blockType} onChange={handleBlockTypeChange} aria-label="Block formatting">
|
||||
<option value="paragraph">Normal</option>
|
||||
<option value="h1">Heading 1</option>
|
||||
<option value="h2">Heading 2</option>
|
||||
<option value="h3">Heading 3</option>
|
||||
<option value="bullet">Bullet List</option>
|
||||
<option value="number">Numbered List</option>
|
||||
<option value="check">Check List</option>
|
||||
<option value="quote">Quote</option>
|
||||
<option value="code">Code Block</option>
|
||||
</select>
|
||||
|
||||
<div className="toolbar-divider" />
|
||||
<div className="toolbar-divider" />
|
||||
|
||||
{/* Inline Styles */}
|
||||
<button
|
||||
type="button"
|
||||
className={isBold ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')}
|
||||
title="Bold (Ctrl+B)"
|
||||
aria-label="Bold"
|
||||
>
|
||||
<Bold className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isItalic ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')}
|
||||
title="Italic (Ctrl+I)"
|
||||
aria-label="Italic"
|
||||
>
|
||||
<Italic className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isUnderline ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline')}
|
||||
title="Underline (Ctrl+U)"
|
||||
aria-label="Underline"
|
||||
>
|
||||
<Underline className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isStrikethrough ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough')}
|
||||
title="Strikethrough"
|
||||
aria-label="Strikethrough"
|
||||
>
|
||||
<Strikethrough className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isCode ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code')}
|
||||
title="Inline Code"
|
||||
aria-label="Inline Code"
|
||||
>
|
||||
<Code className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isLink ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={insertLink}
|
||||
title="Insert Link"
|
||||
aria-label="Link"
|
||||
>
|
||||
<LinkIcon className="h-4 w-4" />
|
||||
</button>
|
||||
{/* Inline Styles */}
|
||||
<button
|
||||
type="button"
|
||||
className={isBold ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')}
|
||||
title="Bold (Ctrl+B)"
|
||||
aria-label="Bold"
|
||||
>
|
||||
<Bold className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isItalic ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')}
|
||||
title="Italic (Ctrl+I)"
|
||||
aria-label="Italic"
|
||||
>
|
||||
<Italic className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isUnderline ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline')}
|
||||
title="Underline (Ctrl+U)"
|
||||
aria-label="Underline"
|
||||
>
|
||||
<Underline className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isStrikethrough ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough')}
|
||||
title="Strikethrough"
|
||||
aria-label="Strikethrough"
|
||||
>
|
||||
<Strikethrough className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isCode ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code')}
|
||||
title="Inline Code"
|
||||
aria-label="Inline Code"
|
||||
>
|
||||
<Code className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={isLink ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={insertLink}
|
||||
title="Insert Link"
|
||||
aria-label="Link"
|
||||
>
|
||||
<LinkIcon className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
<div className="toolbar-divider" />
|
||||
<div className="toolbar-divider" />
|
||||
|
||||
{/* Quick Insert / Block shortcuts */}
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h1' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h1')}
|
||||
title="H1"
|
||||
aria-label="Heading 1"
|
||||
>
|
||||
<Heading1 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h2' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h2')}
|
||||
title="H2"
|
||||
aria-label="Heading 2"
|
||||
>
|
||||
<Heading2 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h3' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h3')}
|
||||
title="H3"
|
||||
aria-label="Heading 3"
|
||||
>
|
||||
<Heading3 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'bullet' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatBulletList}
|
||||
title="Bullet List"
|
||||
aria-label="Bullet List"
|
||||
>
|
||||
<List className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'number' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatNumberedList}
|
||||
title="Numbered List"
|
||||
aria-label="Numbered List"
|
||||
>
|
||||
<ListOrdered className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'check' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatCheckList}
|
||||
title="Check List"
|
||||
aria-label="Check List"
|
||||
>
|
||||
<ListTodo className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'quote' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatQuote}
|
||||
title="Quote"
|
||||
aria-label="Quote"
|
||||
>
|
||||
<Quote className="h-4 w-4" />
|
||||
</button>
|
||||
{/* Quick Insert / Block shortcuts */}
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h1' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h1')}
|
||||
title="H1"
|
||||
aria-label="Heading 1"
|
||||
>
|
||||
<Heading1 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h2' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h2')}
|
||||
title="H2"
|
||||
aria-label="Heading 2"
|
||||
>
|
||||
<Heading2 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'h3' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => formatHeading('h3')}
|
||||
title="H3"
|
||||
aria-label="Heading 3"
|
||||
>
|
||||
<Heading3 className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'bullet' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatBulletList}
|
||||
title="Bullet List"
|
||||
aria-label="Bullet List"
|
||||
>
|
||||
<List className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'number' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatNumberedList}
|
||||
title="Numbered List"
|
||||
aria-label="Numbered List"
|
||||
>
|
||||
<ListOrdered className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'check' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatCheckList}
|
||||
title="Check List"
|
||||
aria-label="Check List"
|
||||
>
|
||||
<ListTodo className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={blockType === 'quote' ? 'active' : ''}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={formatQuote}
|
||||
title="Quote"
|
||||
aria-label="Quote"
|
||||
>
|
||||
<Quote className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
<div className="toolbar-divider" />
|
||||
<div className="toolbar-divider" />
|
||||
|
||||
{/* Clear formatting */}
|
||||
<button
|
||||
type="button"
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={clearFormatting}
|
||||
title="Clear Formatting"
|
||||
aria-label="Clear Formatting"
|
||||
>
|
||||
<RemoveFormatting className="h-4 w-4" />
|
||||
</button>
|
||||
{/* Clear formatting */}
|
||||
<button
|
||||
type="button"
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={clearFormatting}
|
||||
title="Clear Formatting"
|
||||
aria-label="Clear Formatting"
|
||||
>
|
||||
<RemoveFormatting className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{rightContent && (
|
||||
<div className="flex items-center gap-2 ml-auto flex-shrink-0">{rightContent}</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user