@@ -40,6 +40,7 @@ import { api, apiUpload, ApiError } from '../lib/api';
4040import { formatFileSize , formatFileDate , isTextPreviewable , isImagePreviewable , isPreviewable } from '../lib/file-utils' ;
4141import { scrollToFirstError } from '../lib/scroll-to-error' ;
4242import { FilePreviewModal } from '../components/FilePreviewModal' ;
43+ import { FileSystemBrowserModal } from '../components/FileSystemBrowserModal' ;
4344import { AgentAvatar , AgentAvatarPicker , randomPalette , randomIcon , type AvatarConfig } from '../components/AgentAvatar' ;
4445import {
4546 getLatestStreamingAgentChatStream ,
@@ -278,10 +279,7 @@ function AgentFiles({ agentId }: { agentId: string }) {
278279 const [ folderName , setFolderName ] = useState ( '' ) ;
279280 const [ creatingFolder , setCreatingFolder ] = useState ( false ) ;
280281
281- const [ showNewRef , setShowNewRef ] = useState ( false ) ;
282- const [ refName , setRefName ] = useState ( '' ) ;
283- const [ refTarget , setRefTarget ] = useState ( '' ) ;
284- const [ creatingRef , setCreatingRef ] = useState ( false ) ;
282+ const [ showFsBrowser , setShowFsBrowser ] = useState ( false ) ;
285283
286284 const [ deletingPath , setDeletingPath ] = useState < string | null > ( null ) ;
287285 const [ deleteLoading , setDeleteLoading ] = useState ( false ) ;
@@ -320,7 +318,6 @@ function AgentFiles({ agentId }: { agentId: string }) {
320318 function navigateTo ( dirPath : string ) {
321319 setCurrentPath ( dirPath ) ;
322320 setShowNewFolder ( false ) ;
323- setShowNewRef ( false ) ;
324321 setDeletingPath ( null ) ;
325322 }
326323
@@ -347,25 +344,21 @@ function AgentFiles({ agentId }: { agentId: string }) {
347344 }
348345 }
349346
350- async function handleCreateReference ( ) {
351- if ( ! refName . trim ( ) || ! refTarget . trim ( ) ) return ;
352- setCreatingRef ( true ) ;
347+ async function handleCreateReference ( targetPath : string ) {
348+ const name = targetPath . split ( '/' ) . filter ( Boolean ) . pop ( ) ;
349+ if ( ! name ) return ;
350+ setShowFsBrowser ( false ) ;
353351 setError ( '' ) ;
354352 try {
355353 await api ( `/agents/${ agentId } /files/references` , {
356354 method : 'POST' ,
357- body : JSON . stringify ( { path : currentPath , name : refName . trim ( ) , target : refTarget . trim ( ) } ) ,
355+ body : JSON . stringify ( { path : currentPath , name, target : targetPath } ) ,
358356 } ) ;
359- setShowNewRef ( false ) ;
360- setRefName ( '' ) ;
361- setRefTarget ( '' ) ;
362357 setSuccess ( 'Reference created' ) ;
363358 await fetchEntries ( currentPath ) ;
364359 setTimeout ( ( ) => setSuccess ( '' ) , 3000 ) ;
365360 } catch ( err ) {
366361 setError ( err instanceof ApiError ? err . message : 'Failed to create reference' ) ;
367- } finally {
368- setCreatingRef ( false ) ;
369362 }
370363 }
371364
@@ -527,7 +520,6 @@ function AgentFiles({ agentId }: { agentId: string }) {
527520 onClick = { ( ) => {
528521 setShowNewFolder ( ! showNewFolder ) ;
529522 setFolderName ( '' ) ;
530- setShowNewRef ( false ) ;
531523 } }
532524 >
533525 < FolderPlus size = { 14 } />
@@ -536,12 +528,7 @@ function AgentFiles({ agentId }: { agentId: string }) {
536528 < Button
537529 size = "sm"
538530 variant = "ghost"
539- onClick = { ( ) => {
540- setShowNewRef ( ! showNewRef ) ;
541- setRefName ( '' ) ;
542- setRefTarget ( '' ) ;
543- setShowNewFolder ( false ) ;
544- } }
531+ onClick = { ( ) => setShowFsBrowser ( true ) }
545532 >
546533 < Link2 size = { 14 } />
547534 Reference
@@ -573,39 +560,6 @@ function AgentFiles({ agentId }: { agentId: string }) {
573560 </ div >
574561 ) }
575562
576- { showNewRef && (
577- < div className = { styles . filesNewFolderRow } >
578- < div className = { styles . filesNewFolderIcon } >
579- < Link2 size = { 18 } className = { styles . filesIconReference } />
580- </ div >
581- < Input
582- label = ""
583- placeholder = "Reference name"
584- value = { refName }
585- onChange = { ( e ) => setRefName ( e . target . value ) }
586- onKeyDown = { ( e : KeyboardEvent ) => {
587- if ( e . key === 'Escape' ) setShowNewRef ( false ) ;
588- } }
589- />
590- < Input
591- label = ""
592- placeholder = "Target path (e.g. /tmp)"
593- value = { refTarget }
594- onChange = { ( e ) => setRefTarget ( e . target . value ) }
595- onKeyDown = { ( e : KeyboardEvent ) => {
596- if ( e . key === 'Enter' ) handleCreateReference ( ) ;
597- if ( e . key === 'Escape' ) setShowNewRef ( false ) ;
598- } }
599- />
600- < Button size = "sm" onClick = { handleCreateReference } disabled = { creatingRef || ! refName . trim ( ) || ! refTarget . trim ( ) } >
601- { creatingRef ? 'Creating...' : 'Create' }
602- </ Button >
603- < Button size = "sm" variant = "ghost" onClick = { ( ) => setShowNewRef ( false ) } >
604- Cancel
605- </ Button >
606- </ div >
607- ) }
608-
609563 { parentPath !== null && (
610564 < div className = { styles . filesRow } >
611565 < button className = { styles . filesColName } onClick = { ( ) => navigateTo ( parentPath === '/' ? '/' : parentPath ) } >
@@ -712,6 +666,13 @@ function AgentFiles({ agentId }: { agentId: string }) {
712666 onDownload = { ( ) => handleDownload ( previewEntry . path ) }
713667 />
714668 ) }
669+
670+ { showFsBrowser && (
671+ < FileSystemBrowserModal
672+ onSelect = { handleCreateReference }
673+ onClose = { ( ) => setShowFsBrowser ( false ) }
674+ />
675+ ) }
715676 </ div >
716677 ) ;
717678}
0 commit comments