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

formatToolName

Converts MCP tool names to readable format

(toolName: string) => string
example.ts
formatToolName('mcp__server__tool')
// Returns: 'mcp:server:tool'
parseMcpToolName

Extracts 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' }
mapToolToActionType

Maps Claude tool calls to ActionType

(toolName: string) => ActionType
example.ts
mapToolToActionType('bash')
// Returns: 'command_run'

mapToolToActionType('read_file')
// Returns: 'file_read'
generateToolSummary

Creates 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'
extractTextContent

Extracts text from various content formats

(content: unknown) => string
example.ts
extractTextContent([{ type: 'text', text: 'Hello' }])
// Returns: 'Hello'
createToolCall

Creates 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', ... }
updateToolCallWithResult

Updates tool call with execution result

(toolCall: NormalizedToolCall, result: unknown) => NormalizedToolCall
example.ts
updateToolCallWithResult(toolCall, { output: 'file.txt' })
// Returns updated tool call with result
formatFileSize

Formats bytes to human-readable size

(bytes: number) => string
example.ts
formatFileSize(1024)
// Returns: '1 KB'

formatFileSize(1048576)
// Returns: '1 MB'
formatTimestamp

Formats ISO timestamp to readable string

(isoString: string) => string
example.ts
formatTimestamp('2024-01-15T10:30:00Z')
// Returns: '10:30:00 AM'
truncate

Truncates text with ellipsis

(text: string, maxLength: number) => string
example.ts
truncate('This is a long message', 10)
// Returns: 'This is a...'
cn

Class name utility (like clsx)

(...classes: (string | undefined | boolean)[]) => string
example.ts
cn('base-class', isActive && 'active', className)
// Merges class names conditionally