Types
TypeScript type definitions
ASH UI provides comprehensive TypeScript types for all components, tool calls, messages, and actions. Types use discriminated unions for type-safe handling.
Import
import
import type {
NormalizedEntry,
NormalizedToolCall,
ActionType,
ToolStatus,
LogEntry,
} from '@ash-cloud/ash-ui/types';Core Types
ToolStatus
types.ts
type ToolStatus = 'pending' | 'success' | 'failed';ActionType
types.ts
type ActionType =
| 'command_run'
| 'file_read'
| 'file_edit'
| 'file_write'
| 'search'
| 'glob'
| 'web_fetch'
| 'web_search'
| 'mcp_tool'
| 'generic';NormalizedEntry
types.ts
type EntryType =
| 'user_message'
| 'assistant_message'
| 'thinking'
| 'tool_call'
| 'error';
type NormalizedEntry = {
id: string;
timestamp: string;
entryType: EntryType;
content: string;
toolCall?: NormalizedToolCall;
files?: FileAttachment[];
};NormalizedToolCall
types.ts
type NormalizedToolCall = {
id: string;
toolName: string;
actionType: ActionType;
status: ToolStatus;
summary: string;
startedAt?: string;
completedAt?: string;
isError?: boolean;
action: Action; // Discriminated union of action types
};LogEntry
types.ts
type LogLevel = 'info' | 'warn' | 'error' | 'debug';
type LogCategory =
| 'setup'
| 'skills'
| 'execution'
| 'process'
| 'startup';
type LogEntry = {
timestamp: string;
level: LogLevel;
category: LogCategory;
message: string;
data?: Record<string, unknown>;
};Action Types (Discriminated Union)
Each action type has its own interface with specific fields:
types.ts
// Bash command execution
type CommandRunAction = {
type: 'command_run';
command: string;
output?: string;
exitCode?: number;
};
// File read operation
type FileReadAction = {
type: 'file_read';
path: string;
content?: string;
lineCount?: number;
};
// File edit operation
type FileEditAction = {
type: 'file_edit';
path: string;
oldContent?: string;
newContent?: string;
diff?: string;
};
// File write operation
type FileWriteAction = {
type: 'file_write';
path: string;
content?: string;
};
// Code search
type SearchAction = {
type: 'search';
query: string;
results?: SearchResult[];
};
// File glob pattern
type GlobAction = {
type: 'glob';
pattern: string;
matches?: string[];
};
// HTTP request
type WebFetchAction = {
type: 'web_fetch';
url: string;
method?: string;
response?: string;
};
// Web search
type WebSearchAction = {
type: 'web_search';
query: string;
results?: WebSearchResult[];
};
// MCP server tool
type McpToolAction = {
type: 'mcp_tool';
server: string;
tool: string;
args?: Record<string, unknown>;
result?: unknown;
};
// Generic tool call
type GenericToolAction = {
type: 'generic';
args?: Record<string, unknown>;
result?: unknown;
};
// Union of all action types
type Action =
| CommandRunAction
| FileReadAction
| FileEditAction
| FileWriteAction
| SearchAction
| GlobAction
| WebFetchAction
| WebSearchAction
| McpToolAction
| GenericToolAction;Type Guards
Helper functions for narrowing action types:
types.ts
// Check action type
function isCommandRunAction(action: Action): action is CommandRunAction {
return action.type === 'command_run';
}
function isFileReadAction(action: Action): action is FileReadAction {
return action.type === 'file_read';
}
// ... similar guards for all action types
// Usage
if (isCommandRunAction(toolCall.action)) {
console.log(toolCall.action.command); // Type-safe access
console.log(toolCall.action.exitCode); // Available only for CommandRunAction
}Entry Type Guards
types.ts
function isUserMessage(entry: NormalizedEntry): boolean {
return entry.entryType === 'user_message';
}
function isAssistantMessage(entry: NormalizedEntry): boolean {
return entry.entryType === 'assistant_message';
}
function isThinking(entry: NormalizedEntry): boolean {
return entry.entryType === 'thinking';
}
function isToolCall(entry: NormalizedEntry): boolean {
return entry.entryType === 'tool_call';
}
function isError(entry: NormalizedEntry): boolean {
return entry.entryType === 'error';
}