behemoth-cli
Version:
🌍 BEHEMOTH CLIv3.760.4 - Level 50+ POST-SINGULARITY Intelligence Trading AI
177 lines • 10.5 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import DiffPreview from './DiffPreview.js';
import { formatToolParams } from '../../../tools/tools.js';
export default function ToolHistoryItem({ execution }) {
const { name, args, status, result } = execution;
const getStatusIcon = () => {
switch (status) {
case 'completed':
return '🟢';
case 'failed':
return '🔴';
case 'canceled':
return '🚫';
default:
return '?';
}
};
const getToolSource = (toolName) => {
// Extract exchange/service name from tool name
if (toolName.includes('binance'))
return '🟡 Binance';
if (toolName.includes('bybit'))
return '🟠 Bybit';
if (toolName.includes('bitget'))
return '🔵 Bitget';
if (toolName.includes('websearch') || toolName.includes('search'))
return '🌐 Web Search';
if (toolName.includes('ticker') || toolName.includes('behemoth_ticker')) {
// Check args for exchange info
if (args?.exchange) {
const exchange = args.exchange.toLowerCase();
if (exchange === 'binance')
return '🟡 Binance';
if (exchange === 'bybit')
return '🟠 Bybit';
if (exchange === 'bitget')
return '🔵 Bitget';
}
return '📊 Multi-Exchange';
}
if (toolName.includes('cosmic') || toolName.includes('planetary') || toolName.includes('lunar'))
return '🌌 Cosmic Intelligence';
if (toolName.includes('rsi') || toolName.includes('macd') || toolName.includes('technical'))
return '📈 Technical Analysis';
if (toolName.includes('sentiment') || toolName.includes('news'))
return '📰 Sentiment Analysis';
if (toolName.includes('system') || toolName.includes('health') || toolName.includes('performance'))
return '⚙️ System Monitor';
if (toolName.includes('risk') || toolName.includes('kelly') || toolName.includes('var'))
return '🛡️ Risk Management';
// Default fallback
return '🔧 Tool Execution';
};
const getStatusColor = () => {
switch (status) {
case 'completed':
return 'green';
case 'failed':
return 'red';
case 'canceled':
return 'gray';
default:
return 'white';
}
};
const shouldShowDiff = (toolName) => {
return ['create_file', 'edit_file'].includes(toolName);
};
const renderBehemothResult = (content) => {
try {
// Parse the content if it's a string
let data = content;
if (typeof content === 'string') {
try {
data = JSON.parse(content);
}
catch (e) {
// If not JSON, return as formatted string
return _jsx(Text, { color: "cyan", children: content });
}
}
// Check if it's already formatted data (object with emoji keys)
if (typeof data === 'object' && data !== null) {
const keys = Object.keys(data);
const hasEmojiKeys = keys.some(key => /[\u{1F300}-\u{1F9FF}]/u.test(key));
if (hasEmojiKeys) {
// Already formatted - render beautifully
return (_jsx(Box, { flexDirection: "column", children: Object.entries(data).map(([key, value], index) => (_jsxs(Box, { marginY: 0, children: [_jsxs(Text, { color: "cyan", bold: true, children: [key, ": "] }), _jsx(Text, { color: "white", children: String(value) })] }, index))) }));
}
}
// Fallback to JSON display with syntax highlighting
const jsonString = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
// Simple syntax highlighting for JSON
return (_jsx(Box, { flexDirection: "column", children: jsonString.split('\n').map((line, index) => {
if (line.includes('"status"') || line.includes('"success"')) {
return _jsx(Text, { color: "green", children: line }, index);
}
else if (line.includes('"price"') || line.includes('"symbol"')) {
return _jsx(Text, { color: "yellow", children: line }, index);
}
else if (line.includes('"error"') || line.includes('"failed"')) {
return _jsx(Text, { color: "red", children: line }, index);
}
else if (line.includes('"analysis"') || line.includes('"signal"')) {
return _jsx(Text, { color: "magenta", children: line }, index);
}
else if (line.includes(':')) {
return _jsx(Text, { color: "cyan", children: line }, index);
}
else {
return _jsx(Text, { color: "white", children: line }, index);
}
}) }));
}
catch (error) {
return (_jsxs(Box, { children: [_jsx(Text, { color: "red", children: "\uD83D\uDD34 Error formatting BEHEMOTH result: " }), _jsx(Text, { color: "white", children: String(content) })] }));
}
};
const renderResult = (toolName, result) => {
// Handle BEHEMOTH tool outputs with beautiful formatting
if (toolName.startsWith('mcp__behemoth__') || toolName.includes('behemoth_')) {
// Use result.data for BEHEMOTH tools as that's where the formatted data is
const behemothData = result.data || result.content;
return renderBehemothResult(behemothData);
}
const content = result.content;
// Handle execute_command output format
if (typeof content === 'string' && content.includes('stdout:') && content.includes('stderr:')) {
const lines = content.split('\n');
let stdoutLines = [];
let stderrLines = [];
let currentSection = '';
for (const line of lines) {
if (line.startsWith('stdout:')) {
currentSection = 'stdout';
const stdoutContent = line.substring(7).trim();
if (stdoutContent)
stdoutLines.push(stdoutContent);
}
else if (line.startsWith('stderr:')) {
currentSection = 'stderr';
const stderrContent = line.substring(7).trim();
if (stderrContent)
stderrLines.push(stderrContent);
}
else if (currentSection === 'stdout') {
stdoutLines.push(line);
}
else if (currentSection === 'stderr') {
stderrLines.push(line);
}
}
return (_jsxs(_Fragment, { children: [stdoutLines.length > 0 && stdoutLines.some(line => line.trim()) && (_jsx(Text, { color: "white", children: stdoutLines.join('\n').trimEnd() })), stderrLines.length > 0 && stderrLines.some(line => line.trim()) && (_jsx(Text, { color: "yellow", children: stderrLines.join('\n').trimEnd() }))] }));
}
// Handle directory tree output for list_files
if (toolName === 'list_files') {
return (_jsx(Text, { color: "cyan", children: typeof content === 'string' ? content : JSON.stringify(content, null, 2) }));
}
// Handle file content for read_file; don't show content
if (toolName === 'read_file') {
return null;
}
// Handle file content for search_files; don't show content
if (toolName === 'search_files') {
return null;
}
// Default handling
return (_jsx(Text, { color: "white", children: typeof content === 'string' ? content : JSON.stringify(content, null, 2) }));
};
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: getStatusColor(), paddingX: 1, children: [_jsx(Box, { children: _jsxs(Text, { color: getStatusColor(), children: [getStatusIcon(), " ", _jsx(Text, { bold: true, children: getToolSource(name) })] }) }), (name === 'create_tasks' || name === 'update_tasks') && result?.content?.tasks ? (_jsx(Box, { flexDirection: "column", children: result.content.tasks.map((task, index) => {
const statusSymbol = task.status === 'pending' ? '☐' : (task.status === 'in_progress' ? '🔄' : '✓');
const isCompleted = task.status === 'completed';
return (_jsxs(Text, { color: isCompleted ? 'green' : 'white', children: [statusSymbol, " ", task.description] }, task.id || index));
}) })) : formatToolParams(name, args, { includePrefix: false, separator: ': ' }) ? (_jsx(Box, { children: _jsx(Text, { color: "gray", children: formatToolParams(name, args, { includePrefix: false, separator: ': ' }) }) })) : null, shouldShowDiff(name) && status === 'completed' && (_jsx(Box, { children: _jsx(DiffPreview, { toolName: name, toolArgs: args, isHistorical: true }) })), status === 'completed' && result && (_jsx(Box, { children: result.success ? (_jsxs(Box, { flexDirection: "column", children: [result.content && !(name === 'create_tasks' || name === 'update_tasks') && (_jsx(Box, { flexDirection: "column", children: renderResult(name, result) })), result.message && !result.content && !(name === 'create_tasks' || name === 'update_tasks') && (_jsx(Text, { color: "gray", children: result.message }))] })) : (_jsxs(Text, { color: "red", children: ["Tool failed: ", result.error || 'Unknown error'] })) })), status === 'failed' && (_jsx(Box, { children: _jsxs(Text, { color: "red", children: ["Tool execution failed", result?.error && (_jsxs(Text, { color: "gray", children: [' ', "(", result.error, ")"] }))] }) })), status === 'canceled' && (_jsx(Box, { children: _jsx(Text, { color: "gray", children: "Tool execution canceled by user" }) }))] }));
}
//# sourceMappingURL=ToolHistoryItem.js.map