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..70a41243 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 { cn } from '@/ui/lib/utils' +import type { AssetInfo, AssetInfoPaginatedList } from '@shumai/dtos' +import { Link } from '@tanstack/react-router' +import { File, Loader2 } from 'lucide-react' import type { FC } from 'react' -import type { AssetInfoPaginatedList } from '@shumai/dtos' -import { useEffect, useRef } from 'react' +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' 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,52 @@ export const FileViewerLeftSidebar: FC = ({ if (activeFileInView && activeItemRef.current && !hasScrolledRef.current) { activeItemRef.current.scrollIntoView({ block: 'center', + inline: '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/components/file-viewer.tsx b/packages/webui/components/file-viewer.tsx index 05e40708..e5d34234 100644 --- a/packages/webui/components/file-viewer.tsx +++ b/packages/webui/components/file-viewer.tsx @@ -2,8 +2,8 @@ import { useScreenSize } from '@/ui/hooks/useScreenSize' import { getBestTranscode } from '@/ui/lib/media' import type { AssetInfo } from '@shumai/dtos' import { Check, Copy, Download, Minus, Plus } from 'lucide-react' -import type { RefObject } from 'react' -import { useEffect, useRef, useState } from 'react' +import type { ReactNode, RefObject } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import type Player from 'video.js/dist/types/player' import DrawingCanvas from './drawing-canvas' import VideoPlayer from './viewers/video-player' @@ -18,6 +18,7 @@ type FileViewerProps = { onPause?: () => void onTimeUpdate?: (time: number) => void annotations?: Annotation[] + children?: ReactNode } export function FileViewer({ @@ -27,6 +28,7 @@ export function FileViewer({ onPause, onTimeUpdate, annotations, + children, }: FileViewerProps) { const { width: screenWidth } = useScreenSize() const isImage = file.mediaType?.startsWith('image/') @@ -49,11 +51,33 @@ export function FileViewer({ // State for Image Viewer const [containerSize, setContainerSize] = useState({ width: 0, height: 0 }) - const containerRef = useRef(null) const [zoom, setZoom] = useState(1) const [pan, setPan] = useState({ x: 0, y: 0 }) const [copied, setCopied] = useState(false) + const observerRef = useRef(null) + + const containerRef = useCallback((node: HTMLDivElement | null) => { + if (observerRef.current) { + observerRef.current.disconnect() + observerRef.current = null + } + + if (node !== null) { + const observer = new ResizeObserver((entries) => { + const entry = entries[0] + if (entry) { + setContainerSize({ + width: entry.contentRect.width, + height: entry.contentRect.height, + }) + } + }) + observer.observe(node) + observerRef.current = observer + } + }, []) + const imgW = file.media?.metadata?.originalWidth ?? 1920 const imgH = file.media?.metadata?.originalHeight ?? 1080 const conW = containerSize.width @@ -76,22 +100,6 @@ export function FileViewer({ } }, [file.id, conW, conH, isImage, baseScale, imgW, imgH]) - // Resize Observer - useEffect(() => { - if (!containerRef.current) return - const observer = new ResizeObserver((entries) => { - const entry = entries[0] - if (entry) { - setContainerSize({ - width: entry.contentRect.width, - height: entry.contentRect.height, - }) - } - }) - observer.observe(containerRef.current) - return () => observer.disconnect() - }, []) - const handleZoom = (factor: number) => { const cx = conW / 2 const cy = conH / 2 @@ -186,10 +194,28 @@ export function FileViewer({ } } - if (!bestUrl) { + const isUnsupported = !bestUrl || (!isImage && !isVideo) + + if (isUnsupported) { return ( -
-

Preview unavailable

+
+
+ {children} +
+

Preview unavailable

+
+
+
+ +
) } @@ -201,26 +227,29 @@ export function FileViewer({
{isImage && ( <> -
- +
+ {children} +
+ +
{/* Zoom Toolbar */}
@@ -278,7 +307,9 @@ export function FileViewer({ onPause={onPause} onTimeUpdate={onTimeUpdate} annotations={displayAnnotations} - /> + > + {children} + )}
) diff --git a/packages/webui/components/viewers/video-player.tsx b/packages/webui/components/viewers/video-player.tsx index c77b003f..d78594da 100644 --- a/packages/webui/components/viewers/video-player.tsx +++ b/packages/webui/components/viewers/video-player.tsx @@ -53,6 +53,7 @@ interface VideoPlayerProps { onPause?: () => void onTimeUpdate?: (time: number) => void annotations?: Annotation[] + children?: React.ReactNode } type DisplayTranscode = VideoTranscode & { resolution: string } @@ -310,6 +311,7 @@ const VideoPlayer: React.FC = ({ onPause, onTimeUpdate, annotations, + children, }) => { const localPlayerRef = useRef(null) const playerRef = passedPlayerRef || localPlayerRef @@ -797,49 +799,54 @@ const VideoPlayer: React.FC = ({ onMouseMove={handleMouseMove} onMouseLeave={handleMouseLeave} > - {/* Video Area */} -
- {/* Hidden VideoJS container */} -
+
+ {/* Render Carousel/Sidebar here if not fullscreen */} + {!state.isFullScreen && children} - {/* Drawing Canvas (Visible) */} - {videoHtmlEl && containerSize.width > 0 && ( - - )} + {/* Video Area */} +
+ {/* Hidden VideoJS container */} +
- {/* Big Play Button Overlay (when paused) */} - {!state.isPlaying && !isDrawing && ( -
-
- + {/* Drawing Canvas (Visible) */} + {videoHtmlEl && containerSize.width > 0 && ( + + )} + + {/* Big Play Button Overlay (when paused) */} + {!state.isPlaying && !isDrawing && ( +
+
+ +
-
- )} + )} +
(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) const [selectedCommentId, setSelectedCommentId] = useState(null) + const [carouselState, setCarouselState] = useState<{ + show: boolean + files: AssetInfo[] + nextCursor?: string + folderId?: string + }>({ show: false, files: [], nextCursor: undefined, folderId: undefined }) const $patchMetadata = client.api.files[':fileId'].metadata.$patch const { mutate: patchMetadata } = useMutation< InferResponseType, @@ -171,6 +170,92 @@ function FileViewPage() { navigate, ]) + const parentFolderId = + fileData?.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ?? + projectInfo?.rootFolder ?? + '' + + 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]) + if (isLoading && !fileData) { return } @@ -225,28 +310,6 @@ function FileViewPage() { return (
- {!isLeftSidebarCollapsed && ( - <> -
- setIsLeftSidebarCollapsed(true)} - /> -
- { - setLeftSidebarWidth((prev) => Math.max(200, Math.min(500, prev + delta))) - }} - className="hidden md:block" - /> - - )}
{isFetching && (
@@ -259,35 +322,41 @@ function FileViewPage() { onPlay={handlePlay} onTimeUpdate={setCurrentTime} annotations={annotations} + > + {carouselState.show && ( + + )} + +
+ { + setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta))) + }} + className="hidden md:block" + /> +
+ { + if (videoRef.current) { + videoRef.current.pause() + } + }} + selectedCommentId={selectedCommentId} />
- {!isRightSidebarCollapsed && ( - <> - { - setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta))) - }} - className="hidden md:block" - /> -
- { - if (videoRef.current) { - videoRef.current.pause() - } - }} - selectedCommentId={selectedCommentId} - /> -
- - )}
)