Files
hapi/web/src/lib/toolInputUtils.ts
T
weishu cdf8226a9d refactor: extract tool input utility functions into shared module
Move getInputString, getInputStringAny, and truncate functions from
individual ToolCard components into a dedicated toolInputUtils module
to eliminate duplication across PermissionFooter, ToolCard, and
knownTools components.
2026-01-29 14:37:06 +08:00

21 lines
616 B
TypeScript

import { isObject } from '@hapi/protocol'
export function getInputString(input: unknown, key: string): string | null {
if (!isObject(input)) return null
const value = input[key]
return typeof value === 'string' ? value : null
}
export function getInputStringAny(input: unknown, keys: string[]): string | null {
for (const key of keys) {
const value = getInputString(input, key)
if (value) return value
}
return null
}
export function truncate(text: string, maxLen: number): string {
if (text.length <= maxLen) return text
return text.slice(0, maxLen - 3) + '...'
}