refactor: move path utilities to utils directory

This commit is contained in:
weishu
2026-01-05 13:00:48 +08:00
parent d388c92114
commit 77eefcd8da
4 changed files with 3 additions and 4 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
import type { ReactNode } from 'react'
import type { SessionMetadataSummary } from '@/types/api'
import { BulbIcon, ClipboardIcon, EyeIcon, FileDiffIcon, GlobeIcon, PuzzleIcon, QuestionIcon, RocketIcon, SearchIcon, TerminalIcon, WrenchIcon } from '@/components/ToolCard/icons'
import { basename, resolveDisplayPath } from '@/components/ToolCard/path'
import { basename, resolveDisplayPath } from '@/utils/path'
const DEFAULT_ICON_CLASS = 'h-3.5 w-3.5'
// Tool presentation registry for `hapi/web` (aligned with `hapi-app`).
-26
View File
@@ -1,26 +0,0 @@
import type { SessionMetadataSummary } from '@/types/api'
export function resolveDisplayPath(path: string, metadata: SessionMetadataSummary | null): string {
if (!metadata?.path) return path
const root = metadata.path
const lowerPath = path.toLowerCase()
const lowerRoot = root.toLowerCase()
if (!lowerPath.startsWith(lowerRoot)) return path
const remainder = path.slice(root.length)
if (remainder !== '' && !remainder.startsWith('/') && !remainder.startsWith('\\')) return path
let out = remainder
if (out.startsWith('/') || out.startsWith('\\')) {
out = out.slice(1)
}
return out.length === 0 ? '<root>' : out
}
export function basename(path: string): string {
const normalized = path.replace(/\\/g, '/')
const parts = normalized.split('/').filter(Boolean)
return parts.length > 0 ? parts[parts.length - 1] : path
}
@@ -1,5 +1,5 @@
import type { ToolViewProps } from '@/components/ToolCard/views/_all'
import { basename, resolveDisplayPath } from '@/components/ToolCard/path'
import { basename, resolveDisplayPath } from '@/utils/path'
function isObject(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object'
@@ -1,7 +1,7 @@
import type { ToolViewComponent, ToolViewProps } from '@/components/ToolCard/views/_all'
import { CodeBlock } from '@/components/CodeBlock'
import { MarkdownRenderer } from '@/components/MarkdownRenderer'
import { basename, resolveDisplayPath } from '@/components/ToolCard/path'
import { basename, resolveDisplayPath } from '@/utils/path'
function isObject(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object'