mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 07:17:37 +00:00
* 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
159 lines
4.8 KiB
TypeScript
159 lines
4.8 KiB
TypeScript
import { client } from '@/ui/api/client'
|
|
import { ChatbotSidebar } from '@/ui/components/chatbot-sidebar'
|
|
import { FolderTree } from '@/ui/components/folder-tree'
|
|
import { ResizeHandle } from '@/ui/components/resize-handle'
|
|
import { useChatbotStore } from '@/ui/stores/chatbot'
|
|
import { useTopNavStore } from '@/ui/stores/top-nav'
|
|
import { useUiStore } from '@/ui/stores/ui'
|
|
import type { AncestorFolder, AssetInfo } from '@shumai/dtos'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { useEffect, useState } from 'react'
|
|
import { AgentsMdEditor } from './agents-md-editor'
|
|
|
|
export interface AgentsMdManagerProps {
|
|
teamId: string
|
|
projectId: string
|
|
projectName: string
|
|
assetId: string
|
|
rootFolderId: string
|
|
isRoot?: boolean
|
|
}
|
|
|
|
export default function AgentsMdManager({
|
|
teamId,
|
|
projectId,
|
|
projectName,
|
|
assetId,
|
|
rootFolderId,
|
|
isRoot,
|
|
}: AgentsMdManagerProps) {
|
|
const navigate = useNavigate()
|
|
const [leftSidebarWidth, setLeftSidebarWidth] = useState(240)
|
|
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
|
const {
|
|
fileListLeftSidebarCollapsed: isLeftSidebarCollapsed,
|
|
setFileListLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
|
} = useUiStore()
|
|
const { isChatbotOpen, setIsChatbotOpen } = useChatbotStore()
|
|
|
|
const { data: folderInfo } = useQuery({
|
|
queryKey: ['folders', assetId],
|
|
queryFn: async () => {
|
|
const res = await client.api.folders[':folderId'].$get({
|
|
param: { folderId: assetId },
|
|
})
|
|
if (!res.ok) throw new Error('failed to fetch folder')
|
|
return (await res.json()) as unknown as AssetInfo
|
|
},
|
|
enabled: !!assetId,
|
|
})
|
|
|
|
const { setProjectState, clearProjectState } = useTopNavStore()
|
|
|
|
useEffect(() => {
|
|
const isRootFolder = isRoot || assetId === rootFolderId
|
|
const ancestors: AncestorFolder[] = isRootFolder
|
|
? []
|
|
: folderInfo?.name
|
|
? [{ id: assetId, name: folderInfo.name }, ...(folderInfo?.ancestorFolders ?? [])]
|
|
: (folderInfo?.ancestorFolders ?? [])
|
|
|
|
setProjectState({
|
|
teamId,
|
|
projectId,
|
|
projectName,
|
|
ancestorFolders: ancestors,
|
|
currentAsset: { name: folderInfo?.name, type: 'folder' },
|
|
isRootFolder: true,
|
|
customTerminalBreadcrumb: 'AGENTS.md',
|
|
onFolderClick: (id: string) => {
|
|
navigate({
|
|
to: '/projects/$projectId/folders/$folderId',
|
|
params: { projectId, folderId: id },
|
|
})
|
|
},
|
|
})
|
|
|
|
return () => clearProjectState()
|
|
}, [
|
|
teamId,
|
|
projectId,
|
|
projectName,
|
|
folderInfo?.ancestorFolders,
|
|
folderInfo?.name,
|
|
isRoot,
|
|
assetId,
|
|
rootFolderId,
|
|
setProjectState,
|
|
clearProjectState,
|
|
navigate,
|
|
])
|
|
|
|
return (
|
|
<div className="flex-1 flex flex-col h-full overflow-hidden bg-background">
|
|
<div className="flex-1 flex overflow-hidden relative">
|
|
{!isLeftSidebarCollapsed && (
|
|
<div
|
|
className="md:hidden fixed inset-0 bg-black/50 z-40"
|
|
onClick={() => setIsLeftSidebarCollapsed(true)}
|
|
/>
|
|
)}
|
|
{isChatbotOpen && (
|
|
<div
|
|
className="md:hidden fixed inset-0 bg-black/50 z-40"
|
|
onClick={() => setIsChatbotOpen(false)}
|
|
/>
|
|
)}
|
|
|
|
{!isLeftSidebarCollapsed && (
|
|
<>
|
|
<div className="bg-background flex-shrink-0" style={{ width: leftSidebarWidth }}>
|
|
<FolderTree
|
|
teamId={teamId}
|
|
projectId={projectId}
|
|
projectName={projectName}
|
|
rootFolderId={rootFolderId}
|
|
selectedFolderId={assetId}
|
|
ancestorFolders={folderInfo?.ancestorFolders ?? []}
|
|
/>
|
|
</div>
|
|
<ResizeHandle
|
|
onResize={(delta) => {
|
|
setLeftSidebarWidth((prev) => Math.max(180, Math.min(400, prev + delta)))
|
|
}}
|
|
className="hidden md:block"
|
|
/>
|
|
</>
|
|
)}
|
|
|
|
<div className="flex-1 flex flex-col min-w-0 min-h-0 bg-background overflow-hidden p-3">
|
|
<AgentsMdEditor
|
|
projectId={projectId}
|
|
assetId={assetId}
|
|
rootFolderId={rootFolderId}
|
|
isRoot={isRoot}
|
|
/>
|
|
</div>
|
|
|
|
{isChatbotOpen && (
|
|
<>
|
|
<ResizeHandle
|
|
onResize={(delta) => {
|
|
setRightSidebarWidth((prev) => Math.max(240, Math.min(600, prev - delta)))
|
|
}}
|
|
className="hidden md:block"
|
|
/>
|
|
<div
|
|
style={{ width: rightSidebarWidth }}
|
|
className="bg-background flex flex-col flex-shrink-0"
|
|
>
|
|
<ChatbotSidebar projectId={projectId} contextAssetId={assetId} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|