mirror of
https://github.com/langgenius/dify.git
synced 2026-07-14 08:57:02 +08:00
chroe: diectory path
This commit is contained in:
@ -9,7 +9,13 @@ import {
|
||||
} from '@langgenius/dify-ui/dropdown-menu'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export type AgentWorkingDirectoryPath = '.' | '~' | string
|
||||
export const AGENT_WORKING_DIRECTORY_HOME_PATH = '~'
|
||||
export const AGENT_WORKING_DIRECTORY_ROOT_PATH = '.'
|
||||
|
||||
export type AgentWorkingDirectoryPath
|
||||
= | typeof AGENT_WORKING_DIRECTORY_HOME_PATH
|
||||
| typeof AGENT_WORKING_DIRECTORY_ROOT_PATH
|
||||
| string
|
||||
|
||||
type AgentWorkingDirectoryBreadcrumbItemData = {
|
||||
iconClassName: string
|
||||
@ -17,17 +23,15 @@ type AgentWorkingDirectoryBreadcrumbItemData = {
|
||||
path: AgentWorkingDirectoryPath
|
||||
}
|
||||
|
||||
const HOME_DIRECTORY_PATH = '~'
|
||||
|
||||
const normalizeWorkingDirectoryPath = (path: AgentWorkingDirectoryPath) => {
|
||||
if (path === '.' || path === HOME_DIRECTORY_PATH)
|
||||
if (path === AGENT_WORKING_DIRECTORY_ROOT_PATH || path === AGENT_WORKING_DIRECTORY_HOME_PATH)
|
||||
return path
|
||||
|
||||
return path.replace(/^\.\/+/, '').replace(/^\/+|\/+$/g, '')
|
||||
}
|
||||
|
||||
function buildPathFromSegments(segments: string[]) {
|
||||
return segments.length ? segments.join('/') : '.'
|
||||
return segments.length ? segments.join('/') : AGENT_WORKING_DIRECTORY_ROOT_PATH
|
||||
}
|
||||
|
||||
function getBreadcrumbItems({
|
||||
@ -43,13 +47,13 @@ function getBreadcrumbItems({
|
||||
const homeItem: AgentWorkingDirectoryBreadcrumbItemData = {
|
||||
iconClassName: 'i-ri-folder-3-line',
|
||||
label: homeLabel,
|
||||
path: HOME_DIRECTORY_PATH,
|
||||
path: AGENT_WORKING_DIRECTORY_HOME_PATH,
|
||||
}
|
||||
|
||||
if (normalizedPath === HOME_DIRECTORY_PATH)
|
||||
if (normalizedPath === AGENT_WORKING_DIRECTORY_HOME_PATH)
|
||||
return [homeItem]
|
||||
|
||||
const segments = normalizedPath === '.'
|
||||
const segments = normalizedPath === AGENT_WORKING_DIRECTORY_ROOT_PATH
|
||||
? []
|
||||
: normalizedPath.split('/').filter(Boolean)
|
||||
|
||||
@ -58,7 +62,7 @@ function getBreadcrumbItems({
|
||||
{
|
||||
iconClassName: 'i-ri-folder-3-line',
|
||||
label: workingDirectoryLabel,
|
||||
path: '.',
|
||||
path: AGENT_WORKING_DIRECTORY_ROOT_PATH,
|
||||
},
|
||||
...segments.map((segment, index) => ({
|
||||
iconClassName: 'i-ri-folder-3-line',
|
||||
|
||||
@ -10,7 +10,7 @@ import { useTranslation } from 'react-i18next'
|
||||
import { consoleQuery } from '@/service/client'
|
||||
import { getFileIconType } from '../orchestrate/files/file-icon'
|
||||
import { AgentSkillDetailDialog } from '../orchestrate/skills/detail-dialog'
|
||||
import { AgentWorkingDirectoryBreadcrumb } from './working-directory-breadcrumb'
|
||||
import { AGENT_WORKING_DIRECTORY_ROOT_PATH, AgentWorkingDirectoryBreadcrumb } from './working-directory-breadcrumb'
|
||||
|
||||
type AgentWorkingDirectoryPanelProps = {
|
||||
source: AgentWorkingDirectorySource
|
||||
@ -182,7 +182,7 @@ export function AgentWorkingDirectoryPanel({
|
||||
}: AgentWorkingDirectoryPanelProps) {
|
||||
const { t } = useTranslation('agentV2')
|
||||
const { t: tCommon } = useTranslation('common')
|
||||
const [directoryPath, setDirectoryPath] = useState<AgentWorkingDirectoryPath>('.')
|
||||
const [directoryPath, setDirectoryPath] = useState<AgentWorkingDirectoryPath>(AGENT_WORKING_DIRECTORY_ROOT_PATH)
|
||||
const [selectedFileId, setSelectedFileId] = useState<string>()
|
||||
const [loadedFolderPaths, setLoadedFolderPaths] = useState<string[]>([])
|
||||
const [openFolderPaths, setOpenFolderPaths] = useState<string[]>([])
|
||||
|
||||
Reference in New Issue
Block a user