mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: move path utilities to utils directory
This commit is contained in:
@@ -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`).
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user