Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(skills): unify file and folder uploads (#18064)

tobi_klfc4590edce6c
diff --git a/web/src/features/skills/components/SkillEditor.tsx b/web/src/features/skills/components/SkillEditor.tsx
index db192ba159..2ca49f501f 100644
--- a/web/src/features/skills/components/SkillEditor.tsx
+++ b/web/src/features/skills/components/SkillEditor.tsx
@@ -1,6 +1,13 @@
-import { type ComponentProps, useMemo, useState } from "react";
-import { useStore } from "zustand";
+import {
+ type ComponentProps,
+ useCallback,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { useMediaQuery } from "react-responsive";
+import { MAX_SKILL_FILES } from "@langfuse/shared";
+import { useStore } from "zustand";
import {
Download,
Loader2,
@@ -15,11 +22,6 @@ import { CodeMirrorEditor } from "@/src/components/editor";
import Page from "@/src/components/layouts/page";
import { Button } from "@/src/components/ui/button";
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
-import {
- ResizableHandle,
- ResizablePanel,
- ResizablePanelGroup,
-} from "@/src/components/ui/resizable";
import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { createSkillVersionFromDraft } from "@/src/features/skills/actions/createSkillVersion";
@@ -27,7 +29,18 @@ import { downloadSkillVersion } from "@/src/features/skills/actions/downloadSkil
import { saveSkillLabels } from "@/src/features/skills/actions/saveSkillLabels";
import { saveSkillTags } from "@/src/features/skills/actions/saveSkillTags";
import { CreateSkillVersionDialog } from "@/src/features/skills/components/CreateSkillVersionDialog";
-import { SkillFileExplorer } from "@/src/features/skills/components/SkillFileExplorer";
+import { Dropzone } from "@/src/components/design-system/Dropzone/Dropzone";
+import {
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+} from "@/src/components/ui/resizable";
+import {
+ SkillFileExplorer,
+ type SkillFileExplorerState,
+} from "@/src/features/skills/components/SkillFileExplorer";
+import { importSkillFiles } from "@/src/features/skills/actions/importSkillFiles";
+import { getParentFolderPaths } from "@/src/features/skills/components/skillFileTree";
import { getSkillFileLanguageExtensions } from "@/src/features/skills/utils/getSkillFileLanguageExtensions";
import {
createSkillDraftFile,
@@ -46,6 +59,7 @@ import {
SKILL_NAME_RULES,
} from "@/src/features/skills/utils/parseSkillFrontmatterMetadata";
import { api } from "@/src/utils/api";
+import { cn } from "@/src/utils/tailwind";
export function SkillEditor({
projectId,
@@ -147,6 +161,29 @@ export function SkillEditor({
const [isDraft, setIsDraft] = useState(baseVersion === null);
const canEditFiles = isDraft && canCreate && !isSaving;
const isDesktop = useMediaQuery({ query: "(min-width: 768px)" });
+ const [treeState, setTreeState] = useState<SkillFileExplorerState>(() => ({
+ selectedFolder: "",
+ expandedFolders: new Set(store.getState().folders),
+ pendingEntry: null,
+ }));
+ const [isUploadOpen, setIsUploadOpen] = useState(false);
+ const showUpload = canEditFiles && isUploadOpen;
+ const uploadPanelRef = useRef<HTMLElement | null>(null);
+ const focusUploadPanel = useCallback((node: HTMLElement | null) => {
+ uploadPanelRef.current = node;
+ if (!node) return;
+ const previousFocus = document.activeElement;
+ node.focus();
+ return () => {
+ uploadPanelRef.current = null;
+ requestAnimationFrame(() => {
+ if (previousFocus instanceof HTMLElement) previousFocus.focus();
+ });
+ };
+ }, []);
+ const cancelUpload = () => {
+ if (!store.getState().isImporting) setIsUploadOpen(false);
+ };
const createButtonTitle = canCreate
? (createDisabledReason ??
(baseVersion !== null && !dirty
@@ -165,6 +202,7 @@ export function SkillEditor({
(!createNew && (hasNameChanged || !store.getState().dirty))
)
return false;
+ setIsUploadOpen(false);
setIsSaving(true);
try {
const created = await createSkillVersionFromDraft({
@@ -420,49 +458,131 @@ export function SkillEditor({
),
}}
>
- <div className="flex min-h-0 flex-1 flex-col overflow-y-auto md:overflow-hidden">
- <div className="flex min-h-[720px] flex-1 flex-col overflow-hidden border-t md:min-h-[560px] md:flex-row">
- {history.kind === "versions" ? (
- <SkillVersionHistory
- {...history}
- dirty={dirty}
- isDraft={isDraft}
- canEdit={canCreate}
- labelOptions={metadataOptions.labels}
- isSavingLabels={setVersionLabels.isPending}
- onSaveLabels={saveLabels}
- />
- ) : (
- <SkillVersionHistory kind="new" />
- )}
- <div className="min-h-[720px] min-w-0 flex-1 md:min-h-0">
- <ResizablePanelGroup
- key={isDesktop ? "desktop" : "mobile"}
- orientation={isDesktop ? "horizontal" : "vertical"}
- >
- <ResizablePanel
- defaultSize={isDesktop ? "28%" : "32%"}
- minSize={isDesktop ? "20%" : "24%"}
- maxSize={isDesktop ? "42%" : "50%"}
+ <div className="grid min-h-0 flex-1 grid-cols-1 grid-rows-1">
+ {showUpload ? (
+ <section
+ ref={focusUploadPanel}
+ tabIndex={-1}
+ aria-label="Upload files"
+ aria-busy={isImporting}
+ className="bg-background flex min-h-0 flex-col gap-3 p-4 outline-none [grid-area:1/1]"
+ onKeyDown={(event) => {
+ if (event.key === "Escape") {
+ event.preventDefault();
+ event.stopPropagation();
+ cancelUpload();
+ }
+ }}
+ >
+ <div className="flex items-center justify-between gap-2">
+ <div>
+ <p className="text-sm font-bold">Upload files or folders</p>
+ {isImporting ? (
+ <p
+ role="status"
+ className="text-muted-foreground text-sm"
+ >
+ Adding files to draft…
+ </p>
+ ) : null}
+ </div>
+ <Button
+ type="button"
+ variant="ghost"
+ disabled={isImporting}
+ onClick={cancelUpload}
>
- <SkillFileExplorer
- store={store}
- readOnly={!isDraft || !canCreate}
- disabled={isSaving}
- />
- </ResizablePanel>
- <ResizableHandle withHandle />
- <ResizablePanel
- defaultSize={isDesktop ? "72%" : "68%"}
- minSize={isDesktop ? "45%" : "42%"}
+ Cancel
+ </Button>
+ </div>
+ <div className="flex min-h-0 flex-1">
+ <Dropzone
+ src={undefined}
+ variant="panel"
+ accept={undefined}
+ maxFiles={MAX_SKILL_FILES}
+ maxSize={undefined}
+ minSize={undefined}
+ isDisabled={isImporting}
+ onError={(error) => {
+ showErrorToast("Could not add files", error.message);
+ uploadPanelRef.current?.focus();
+ }}
+ onDrop={async (files) => {
+ store.setState({ isImporting: true });
+ try {
+ const paths = await importSkillFiles(store, files);
+ setTreeState((current) => ({
+ selectedFolder: "",
+ pendingEntry: null,
+ expandedFolders: new Set([
+ ...current.expandedFolders,
+ ...getParentFolderPaths(paths),
+ ]),
+ }));
+ setIsUploadOpen(false);
+ } finally {
+ store.setState({ isImporting: false });
+ }
+ }}
+ />
+ </div>
+ </section>
+ ) : null}
+ <div
+ className={cn(
+ "flex min-h-0 flex-1 flex-col overflow-y-auto [grid-area:1/1] md:overflow-hidden",
+ showUpload && "invisible",
+ )}
+ inert={showUpload}
+ aria-hidden={showUpload}
+ >
+ <div className="flex min-h-[720px] flex-1 flex-col overflow-hidden border-t md:min-h-[560px] md:flex-row">
+ {history.kind === "versions" ? (
+ <SkillVersionHistory
+ {...history}
+ dirty={dirty}
+ isDraft={isDraft}
+ canEdit={canCreate}
+ labelOptions={metadataOptions.labels}
+ isSavingLabels={setVersionLabels.isPending}
+ onSaveLabels={saveLabels}
+ />
+ ) : (
+ <SkillVersionHistory kind="new" />
+ )}
+ <div className="min-h-[720px] min-w-0 flex-1 md:min-h-0">
+ <ResizablePanelGroup
+ key={isDesktop ? "desktop" : "mobile"}
+ orientation={isDesktop ? "horizontal" : "vertical"}
>
- <SkillFileEditor
- projectId={projectId}
- store={store}
- editable={canEditFiles}
- />
- </ResizablePanel>
- </ResizablePanelGroup>
+ <ResizablePanel
+ defaultSize={isDesktop ? "28%" : "32%"}
+ minSize={isDesktop ? "20%" : "24%"}
+ maxSize={isDesktop ? "42%" : "50%"}
+ >
+ <SkillFileExplorer
+ store={store}
+ readOnly={!isDraft || !canCreate}
+ disabled={isSaving}
+ state={treeState}
+ onStateChange={setTreeState}
+ onUpload={() => setIsUploadOpen(true)}
+ />
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel
+ defaultSize={isDesktop ? "72%" : "68%"}
+ minSize={isDesktop ? "45%" : "42%"}
+ >
+ <SkillFileEditor
+ projectId={projectId}
+ store={store}
+ editable={canEditFiles}
+ />
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ </div>
</div>
</div>
</div>
diff --git a/web/src/features/skills/components/SkillFileExplorer.tsx b/web/src/features/skills/components/SkillFileExplorer.tsx
index c4f4b13cdf..dc2a0c0f1b 100644
--- a/web/src/features/skills/components/SkillFileExplorer.tsx
+++ b/web/src/features/skills/components/SkillFileExplorer.tsx
@@ -1,4 +1,9 @@
-import { useId, useState, type ReactNode } from "react";
+import {
+ useId,
+ type ReactNode,
+ type Dispatch,
+ type SetStateAction,
+} from "react";
import { useStore } from "zustand";
import { useShallow } from "zustand/react/shallow";
import {
@@ -39,11 +44,7 @@ import {
import { Button } from "@/src/components/ui/button";
import { Input } from "@/src/components/ui/input";
import { IconButton } from "@/src/components/design-system/IconButton/IconButton";
-import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
-import { DropzoneController } from "@/src/components/design-system/DropzoneController/DropzoneController";
-import { Tooltip } from "@/src/components/design-system/Tooltip/Tooltip";
import { showErrorToast } from "@/src/features/notifications";
-import { importSkillFiles } from "@/src/features/skills/actions/importSkillFiles";
import {
buildSkillFileTree,
getParentFolderPaths,
@@ -54,6 +55,7 @@ import {
type SkillEditorStore,
} from "@/src/features/skills/components/skillEditorStore";
import { cn } from "@/src/utils/tailwind";
+import { Tooltip } from "@/src/components/design-system/Tooltip/Tooltip";
type PendingEntry = {
kind: "file" | "folder";
@@ -61,14 +63,26 @@ type PendingEntry = {
name: string;
};
+export type SkillFileExplorerState = {
+ selectedFolder: string;
+ expandedFolders: Set<string>;
+ pendingEntry: PendingEntry | null;
+};
+
export function SkillFileExplorer({
store,
disabled = false,
readOnly = false,
+ state,
+ onStateChange,
+ onUpload,
}: {
store: SkillEditorStore;
disabled?: boolean;
readOnly?: boolean;
+ state: SkillFileExplorerState;
+ onStateChange: Dispatch<SetStateAction<SkillFileExplorerState>>;
+ onUpload: () => void;
}) {
const filePaths = useStore(
store,
@@ -77,11 +91,17 @@ export function SkillFileExplorer({
const folders = useStore(store, (state) => state.folders);
const activePath = useStore(store, (state) => state.activePath);
const actions = useStore(store, (state) => state.actions);
- const [selectedFolder, setSelectedFolder] = useState("");
- const [expandedFolders, setExpandedFolders] = useState(
- () => new Set(store.getState().folders),
- );
- const [pendingEntry, setPendingEntry] = useState<PendingEntry | null>(null);
+ const { selectedFolder, expandedFolders, pendingEntry } = state;
+ const setSelectedFolder = (selectedFolder: string) =>
+ onStateChange((current) => ({ ...current, selectedFolder }));
+ const setPendingEntry = (pendingEntry: PendingEntry | null) =>
+ onStateChange((current) => ({ ...current, pendingEntry }));
+ const setExpandedFolders = (update: SetStateAction<Set<string>>) =>
+ onStateChange((current) => ({
+ ...current,
+ expandedFolders:
+ typeof update === "function" ? update(current.expandedFolders) : update,
+ }));
const isImporting = useStore(store, (state) => state.isImporting);
const tree = buildSkillFileTree(filePaths, folders);
const sensors = useSensors(
@@ -320,131 +340,70 @@ export function SkillFileExplorer({
collisionDetection={skillMoveCollisionDetection}
onDragEnd={handleDragEnd}
>
- <DropzoneController
- noClick
- noKeyboard
- isDisabled={moveDisabled}
- onError={(error) =>
- showErrorToast("Could not add files", error.message)
- }
- onProcessingChange={(isImporting) => store.setState({ isImporting })}
- onDrop={async (droppedFiles) => {
- const paths = await importSkillFiles(store, droppedFiles);
- setExpandedFolders(
- (current) =>
- new Set([...current, ...getParentFolderPaths(paths)]),
- );
- setSelectedFolder("");
- setPendingEntry(null);
- }}
+ <aside
+ aria-label="Skill files"
+ className="ph-no-capture bg-muted/20 relative flex h-full min-w-0 flex-col"
>
- {({
- getRootProps,
- getInputProps,
- isDragActive,
- open,
- openDirectory,
- }) => (
- <aside
- {...getRootProps({
- role: "region",
- "aria-label": "Skill files",
- className: cn(
- "ph-no-capture bg-muted/20 relative flex h-full min-w-0 flex-col",
- isDragActive && "ring-primary ring-2 ring-inset",
- ),
- })}
- >
- <input {...getInputProps()} aria-label="Add files to draft" />
- <div className="flex min-h-11 items-center justify-between gap-2 border-b px-3">
- <SkillFolderDropTarget path="" disabled={moveDisabled}>
- <button
- type="button"
- aria-label="Root folder"
- title="Drop a file here to move it to the root"
- onClick={() => setSelectedFolder("")}
- className="flex items-center gap-2 rounded px-1 py-2 text-sm font-bold"
- >
- <FolderOpen className="h-4 w-4" /> Files
- </button>
- </SkillFolderDropTarget>
- {!readOnly ? (
- <div className="flex items-center gap-0.5">
- <DropdownMenu
- disabled={disabled || isImporting}
- items={[
- {
- id: "files",
- type: "item",
- title: "Add files",
- icon: FilePlus2,
- onClick: open,
- },
- {
- id: "folder",
- type: "item",
- title: "Add folder",
- icon: FolderPlus,
- onClick: openDirectory,
- },
- ]}
- >
- {({ getTriggerProps }) => (
- <IconButton
- {...getTriggerProps()}
- icon={Upload}
- label="Upload files or folder"
- size="sm"
- disabled={disabled || isImporting}
- />
- )}
- </DropdownMenu>
- <Button
- type="button"
- variant="ghost"
- size="icon-sm"
- title="New file"
- aria-label="New file"
- disabled={moveDisabled}
- onClick={() => startEntry("file")}
- >
- <FilePlus2 className="h-4 w-4" />
- </Button>
- <Button
- type="button"
- variant="ghost"
- size="icon-sm"
- title="New folder"
- aria-label="New folder"
- disabled={moveDisabled}
- onClick={() => startEntry("folder")}
- >
- <FolderPlus className="h-4 w-4" />
- </Button>
- </div>
- ) : null}
- </div>
- <div className="flex flex-1 flex-col overflow-y-auto p-2">
- {renderTree(tree, "")}
- <SkillFolderDropTarget
- path=""
+ <div className="flex min-h-11 items-center justify-between gap-2 border-b px-3">
+ <SkillFolderDropTarget path="" disabled={moveDisabled}>
+ <button
+ type="button"
+ aria-label="Root folder"
+ title="Drop a file here to move it to the root"
+ onClick={() => setSelectedFolder("")}
+ className="flex items-center gap-2 rounded px-1 py-2 text-sm font-bold"
+ >
+ <FolderOpen className="h-4 w-4" /> Files
+ </button>
+ </SkillFolderDropTarget>
+ {!readOnly ? (
+ <div className="flex items-center gap-0.5">
+ <IconButton
+ onClick={onUpload}
+ icon={Upload}
+ label="Upload files or folders"
+ size="sm"
disabled={moveDisabled}
- variant="empty-space"
/>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-sm"
+ title="New file"
+ aria-label="New file"
+ disabled={moveDisabled}
+ onClick={() => startEntry("file")}
+ >
+ <FilePlus2 className="h-4 w-4" />
+ </Button>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-sm"
+ title="New folder"
+ aria-label="New folder"
+ disabled={moveDisabled}
+ onClick={() => startEntry("folder")}
+ >
+ <FolderPlus className="h-4 w-4" />
+ </Button>
</div>
- {isImporting ? (
- <p className="text-muted-foreground border-t px-3 py-2 text-xs leading-4">
- Adding files to draft…
- </p>
- ) : null}
- {isDragActive ? (
- <div className="bg-background/90 pointer-events-none absolute inset-0 flex items-center justify-center p-4 text-center text-sm font-bold">
- Drop files or folders to add to draft
- </div>
- ) : null}
- </aside>
- )}
- </DropzoneController>
+ ) : null}
+ </div>
+ <div className="flex flex-1 flex-col overflow-y-auto p-2">
+ {renderTree(tree, "")}
+ <SkillFolderDropTarget
+ path=""
+ disabled={moveDisabled}
+ variant="empty-space"
+ />
+ </div>
+ {isImporting ? (
+ <p className="text-muted-foreground border-t px-3 py-2 text-xs leading-4">
+ Adding files to draft…
+ </p>
+ ) : null}
+ </aside>
</DndContext>
</div>
);