diff --git a/packages/agent/src/index.test.ts b/packages/agent/src/index.test.ts index 20909091..78f162ef 100644 --- a/packages/agent/src/index.test.ts +++ b/packages/agent/src/index.test.ts @@ -203,11 +203,13 @@ describe('Sandbox Network isolation integration', () => { // Mock SandboxManager.initialize to behave like a process-global singleton let registeredCallback: SandboxAskCallback | null = null - const initializeSpy = vi.spyOn(SandboxManager, 'initialize').mockImplementation(async (config, cb) => { - if (!registeredCallback) { - registeredCallback = cb || null - } - }) + const initializeSpy = vi + .spyOn(SandboxManager, 'initialize') + .mockImplementation(async (config, cb) => { + if (!registeredCallback) { + registeredCallback = cb || null + } + }) const resetSpy = vi.spyOn(SandboxManager, 'reset').mockImplementation(async () => { // In the real SandboxManager, reset clears the global initialization promise and servers, // which allows subsequent initialize calls to register a new callback. diff --git a/packages/webui/components/breadcrumb-nav.tsx b/packages/webui/components/breadcrumb-nav.tsx index a79aa2b6..076aedb8 100644 --- a/packages/webui/components/breadcrumb-nav.tsx +++ b/packages/webui/components/breadcrumb-nav.tsx @@ -240,65 +240,67 @@ export function BreadcrumbNav({ )} -
- {/* Left Sidebar Toggle */} - {!isPublic && onLeftSidebarToggle && ( + {!fileId && ( +
+ {/* Left Sidebar Toggle */} + {!isPublic && onLeftSidebarToggle && ( + + )} + + {/* Card View */} + {!isPublic && displayStyle && onDisplayStyleChange && ( + <> + + + {/* List View */} + + + )} + + {/* Right Sidebar Toggle */} - )} - - {/* Card View */} - {!isPublic && displayStyle && onDisplayStyleChange && ( - <> - - - {/* List View */} - - - )} - - {/* Right Sidebar Toggle */} - -
+
+ )} ) } diff --git a/packages/webui/components/chat/message-input.tsx b/packages/webui/components/chat/message-input.tsx index 39907195..4b82209b 100644 --- a/packages/webui/components/chat/message-input.tsx +++ b/packages/webui/components/chat/message-input.tsx @@ -457,125 +457,126 @@ export const ChatInput = React.forwardRef( cursor: text; } `} - {showMentionList && (membersLoading || filteredAgents.length > 0 || filteredHumans.length > 0) && ( -
-
- {membersLoading ? ( -
- {/* Agents Skeleton */} -
-
- + {showMentionList && + (membersLoading || filteredAgents.length > 0 || filteredHumans.length > 0) && ( +
+
+ {membersLoading ? ( +
+ {/* Agents Skeleton */} +
+
+ +
+
+ + +
+
+ + +
-
- - -
-
- - + {/* Members Skeleton */} +
+
+ +
+
+ + +
+
+ + +
- {/* Members Skeleton */} -
-
- -
-
- - -
-
- - -
-
-
- ) : ( - <> - {filteredAgents.length > 0 && ( - <> - - {!collapsedSections.bots && - filteredAgents.map((item, index) => { - const actualIndex = index - return ( - - ) - })} - - )} + ) : ( + <> + {filteredAgents.length > 0 && ( + <> + + {!collapsedSections.bots && + filteredAgents.map((item, index) => { + const actualIndex = index + return ( + + ) + })} + + )} - {filteredHumans.length > 0 && ( - <> - - {!collapsedSections.users && - filteredHumans.map((item, index) => { - const actualIndex = - (collapsedSections.bots ? 0 : filteredAgents.length) + index - return ( - - ) - })} - - )} - - )} + {filteredHumans.length > 0 && ( + <> + + {!collapsedSections.users && + filteredHumans.map((item, index) => { + const actualIndex = + (collapsedSections.bots ? 0 : filteredAgents.length) + index + return ( + + ) + })} + + )} + + )} +
-
- )} + )} {showUpperPart && (
diff --git a/packages/webui/components/file-viewer-left-sidebar.tsx b/packages/webui/components/file-viewer-left-sidebar.tsx index 2ade37c2..2113360c 100644 --- a/packages/webui/components/file-viewer-left-sidebar.tsx +++ b/packages/webui/components/file-viewer-left-sidebar.tsx @@ -1,26 +1,40 @@ import { client } from '@/ui/api/client' -import { useInfiniteQuery } from '@tanstack/react-query' -import { Loader2, PanelLeftClose } from 'lucide-react' +import { File, Loader2 } from 'lucide-react' import type { FC } from 'react' -import type { AssetInfoPaginatedList } from '@shumai/dtos' -import { useEffect, useRef } from 'react' +import type { AssetInfo, AssetInfoPaginatedList } from '@shumai/dtos' +import { useEffect, useRef, useState } from 'react' import { useInView } from 'react-intersection-observer' -import { SidebarFileCard } from './sidebar-file-card' -import { Button } from './ui/button' -import { ScrollArea } from './ui/scroll-area' +import { Link } from '@tanstack/react-router' +import { cn } from '@/ui/lib/utils' interface FileViewerLeftSidebarProps { projectId: string currentAssetId: string parentFolderId: string - onCollapse: () => void + initialFiles: AssetInfo[] + initialNextCursor: string | undefined +} + +export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => { + if (item.preview?.thumbnailUrl) { + return ( + Preview + ) + } + + return ( +
+ +
+ ) } export const FileViewerLeftSidebar: FC = ({ projectId, currentAssetId, parentFolderId, - onCollapse, + initialFiles, + initialNextCursor, }) => { const { ref, inView } = useInView({ threshold: 0, @@ -29,38 +43,51 @@ export const FileViewerLeftSidebar: FC = ({ const activeItemRef = useRef(null) const hasScrolledRef = useRef(false) - const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = useInfiniteQuery({ - queryKey: [ - 'folders', - parentFolderId, - 'children', - { - assetType: 'file', - }, - ], - queryFn: async ({ pageParam }) => { - const res = await client.api.folders[':folderId'].children.$get({ - param: { folderId: parentFolderId }, - query: { - assetType: 'file', - after: pageParam, - first: '20', - }, - }) - if (!res.ok) throw new Error('failed to fetch folder children') - return (await res.json()) as unknown as AssetInfoPaginatedList - }, - initialPageParam: '', - getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, - }) - - const files = data?.pages.flatMap((page) => page.data) ?? [] + const [files, setFiles] = useState(initialFiles) + const [nextCursor, setNextCursor] = useState(initialNextCursor) + const [hasMore, setHasMore] = useState(!!initialNextCursor) + const [isFetchingNext, setIsFetchingNext] = useState(false) + // Sync state if initial files / cursor changes (due to parent folder change) useEffect(() => { - if (inView && hasNextPage && !isFetchingNextPage) { - fetchNextPage() + setFiles(initialFiles) + setNextCursor(initialNextCursor) + setHasMore(!!initialNextCursor) + hasScrolledRef.current = false + }, [initialFiles, initialNextCursor]) + + // Fetch next page when scrolling near bottom + useEffect(() => { + const fetchNextPage = async () => { + if (!nextCursor || isFetchingNext || !inView || !hasMore) return + setIsFetchingNext(true) + try { + const res = await client.api.folders[':folderId'].search.$post({ + param: { folderId: parentFolderId }, + json: { + assetType: 'file', + after: nextCursor, + first: 200, + recursively: false, + conditions: [], + }, + }) + if (!res.ok) throw new Error('Failed to fetch next page') + const result = (await res.json()) as unknown as AssetInfoPaginatedList + const batchFiles = (result.data || []) as AssetInfo[] + + setFiles((prev) => [...prev, ...batchFiles]) + setNextCursor(result.pageInfo?.cursor || undefined) + setHasMore(!!result.pageInfo?.cursor && batchFiles.length > 0) + } catch (err) { + console.error('Error fetching next page:', err) + } finally { + setIsFetchingNext(false) + } } - }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]) + + fetchNextPage() + }, [inView, nextCursor, hasMore, isFetchingNext, parentFolderId]) // Reset scroll lock when current asset changes useEffect(() => { @@ -73,47 +100,48 @@ export const FileViewerLeftSidebar: FC = ({ if (activeFileInView && activeItemRef.current && !hasScrolledRef.current) { activeItemRef.current.scrollIntoView({ block: 'center', + behavior: 'smooth', }) hasScrolledRef.current = true } }, [files, currentAssetId]) return ( -
-
-

Current Folder

- -
- -
- {isLoading && ( -
- +
+
+ {files.map((file) => { + if (!file) return null + const isActive = file.id === currentAssetId + return ( +
+ + +
- )} - {files.map( - (file) => - file && ( - - ), - )} -
- {isFetchingNextPage && ( -
- -
- )} + ) + })} + + {/* Infinite Scroll Trigger */} + {hasMore && ( +
+ {isFetchingNext && }
-
- + )} +
) } diff --git a/packages/webui/routes/projects/$projectId/files/$fileId.tsx b/packages/webui/routes/projects/$projectId/files/$fileId.tsx index 48be52aa..3278f4d4 100644 --- a/packages/webui/routes/projects/$projectId/files/$fileId.tsx +++ b/packages/webui/routes/projects/$projectId/files/$fileId.tsx @@ -7,12 +7,11 @@ import { FileDetailSkeleton } from '@/ui/components/loading-skeletons' import { useMemberStore } from '@/ui/stores/members' import { useTeamContextStore } from '@/ui/stores/team-context' import { useTopNavStore } from '@/ui/stores/top-nav' -import { useUiStore } from '@/ui/stores/ui' import { type Annotation } from '@/ui/types' import { useMutation } from '@tanstack/react-query' import { InferRequestType, InferResponseType } from 'hono/client' -import type { AssetInfo, CommentInfo } from '@shumai/dtos' +import type { AssetInfo, AssetInfoPaginatedList, CommentInfo } from '@shumai/dtos' import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query' import { createFileRoute, useNavigate } from '@tanstack/react-router' import { Loader2 } from 'lucide-react' @@ -26,13 +25,7 @@ function FileViewPage() { const activeFileId = versionAssetId || fileId const videoRef = useRef(null) - const { - fileViewRightSidebarCollapsed: isRightSidebarCollapsed, - fileViewLeftSidebarCollapsed: isLeftSidebarCollapsed, - setFileViewLeftSidebarCollapsed: setIsLeftSidebarCollapsed, - } = useUiStore() const { teamId, ensureTeamIdForProject } = useTeamContextStore() - const [leftSidebarWidth, setLeftSidebarWidth] = useState(280) const [rightSidebarWidth, setRightSidebarWidth] = useState(360) const [annotations, setAnnotations] = useState([]) const [currentTime, setCurrentTime] = useState(0) @@ -222,30 +215,110 @@ function FileViewPage() { setSelectedCommentId(null) } + const parentFolderId = + fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ?? + projectInfo.rootFolder ?? + '' + + const [carouselState, setCarouselState] = useState<{ + show: boolean + files: AssetInfo[] + nextCursor?: string + folderId?: string + }>({ show: false, files: [], nextCursor: undefined, folderId: undefined }) + + useEffect(() => { + if (!parentFolderId || !activeFileId) return + if (carouselState.folderId === parentFolderId) { + return + } + + let isMounted = true + + const fetchCarouselData = async () => { + try { + let cursor = '' + let found = false + const allFiles: AssetInfo[] = [] + let lastCursor: string | undefined = undefined + + for (let batch = 0; batch < 5; batch++) { + const res = await client.api.folders[':folderId'].search.$post({ + param: { folderId: parentFolderId }, + json: { + assetType: 'file', + after: cursor, + first: 200, + recursively: false, + conditions: [], + }, + }) + if (!res.ok) { + throw new Error('Failed to search parent folder for carousel') + } + const result = (await res.json()) as unknown as AssetInfoPaginatedList + const batchFiles = (result.data || []) as AssetInfo[] + allFiles.push(...batchFiles) + + if (batchFiles.some((f) => f.id === activeFileId)) { + found = true + lastCursor = result.pageInfo?.cursor || undefined + break + } + if (!result.pageInfo?.cursor || batchFiles.length < 200) { + break + } + cursor = result.pageInfo.cursor + } + + if (isMounted) { + if (found) { + setCarouselState({ + show: true, + files: allFiles, + nextCursor: lastCursor, + folderId: parentFolderId, + }) + } else { + setCarouselState({ + show: false, + files: [], + nextCursor: undefined, + folderId: parentFolderId, + }) + } + } + } catch (err) { + console.error(err) + if (isMounted) { + setCarouselState({ + show: false, + files: [], + nextCursor: undefined, + folderId: parentFolderId, + }) + } + } + } + + fetchCarouselData() + + return () => { + isMounted = false + } + }, [parentFolderId, activeFileId, carouselState.folderId]) + return (
- {!isLeftSidebarCollapsed && ( - <> -
- setIsLeftSidebarCollapsed(true)} - /> -
- { - setLeftSidebarWidth((prev) => Math.max(200, Math.min(500, prev + delta))) - }} - className="hidden md:block" - /> - + {carouselState.show && ( + )}
{isFetching && ( @@ -261,33 +334,29 @@ function FileViewPage() { annotations={annotations} />
- {!isRightSidebarCollapsed && ( - <> - { - setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta))) - }} - className="hidden md:block" - /> -
- { - if (videoRef.current) { - videoRef.current.pause() - } - }} - selectedCommentId={selectedCommentId} - /> -
- - )} + { + setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta))) + }} + className="hidden md:block" + /> +
+ { + if (videoRef.current) { + videoRef.current.pause() + } + }} + selectedCommentId={selectedCommentId} + /> +
)