Utilities
Helper functions for working with agent data
ASH UI provides utility functions for formatting tool names, creating normalized tool calls, parsing results, and other common operations when building agent interfaces.
Import
import
import {
formatToolName,
createToolCall,
mapToolToActionType,
// ... other utilities
} from '@ash-cloud/ash-ui/utils';Available Functions
formatToolNameConverts MCP tool names to readable format
(toolName: string) => string
example.ts
formatToolName('mcp__server__tool')
// Returns: 'mcp:server:tool'parseMcpToolNameExtracts server and tool names from MCP format
(toolName: string) => { server: string; tool: string } | null
example.ts
parseMcpToolName('mcp__myserver__mytool')
// Returns: { server: 'myserver', tool: 'mytool' }mapToolToActionTypeMaps Claude tool calls to ActionType
(toolName: string) => ActionType
example.ts
mapToolToActionType('bash')
// Returns: 'command_run'
mapToolToActionType('read_file')
// Returns: 'file_read'generateToolSummaryCreates a human-readable summary for tool calls
(toolName: string, args: Record<string, unknown>) => string
example.ts
generateToolSummary('bash', { command: 'npm install' })
// Returns: 'Running npm install'extractTextContentExtracts text from various content formats
(content: unknown) => string
example.ts
extractTextContent([{ type: 'text', text: 'Hello' }])
// Returns: 'Hello'createToolCallCreates a normalized tool call object
(id: string, toolName: string, args: Record<string, unknown>) => NormalizedToolCall
example.ts
createToolCall('tc_1', 'bash', { command: 'ls' })
// Returns: { id: 'tc_1', toolName: 'bash', ... }updateToolCallWithResultUpdates tool call with execution result
(toolCall: NormalizedToolCall, result: unknown) => NormalizedToolCall
example.ts
updateToolCallWithResult(toolCall, { output: 'file.txt' })
// Returns updated tool call with resultformatFileSizeFormats bytes to human-readable size
(bytes: number) => string
example.ts
formatFileSize(1024)
// Returns: '1 KB'
formatFileSize(1048576)
// Returns: '1 MB'formatTimestampFormats ISO timestamp to readable string
(isoString: string) => string
example.ts
formatTimestamp('2024-01-15T10:30:00Z')
// Returns: '10:30:00 AM'truncateTruncates text with ellipsis
(text: string, maxLength: number) => string
example.ts
truncate('This is a long message', 10)
// Returns: 'This is a...'cnClass name utility (like clsx)
(...classes: (string | undefined | boolean)[]) => string
example.ts
cn('base-class', isActive && 'active', className)
// Merges class names conditionally