/**
 * NormalizedEntry → LogEntry 类型映射
 * 将后端标准化日志转换为前端 UI 组件可用的格式
 */
// ============ UI 层日志类型 (来自 design/agent-tower/types.ts) ============
export var LogType;
(function (LogType) {
    LogType["Action"] = "Action";
    LogType["Assistant"] = "Assistant";
    LogType["Info"] = "Info";
    LogType["Tool"] = "Tool";
    LogType["User"] = "User";
    LogType["Cursor"] = "Cursor";
    LogType["Error"] = "Error"; // ✗ Error Message
})(LogType || (LogType = {}));
// ============ 映射函数 ============
/**
 * 获取工具调用的显示标题
 */
function getToolTitle(entry) {
    const toolName = entry.metadata?.toolName || 'Tool';
    const action = entry.metadata?.action;
    const status = entry.metadata?.status;
    // 根据 action 类型生成更友好的标题
    const actionLabels = {
        file_read: 'Read File',
        file_edit: 'Edit File',
        command_run: 'Run Command',
        search: 'Search',
        web_fetch: 'Fetch URL',
        tool: 'Tool',
        task_create: 'Create Task',
        plan_presentation: 'Present Plan',
        todo_management: 'Manage Todo',
        other: 'Action',
    };
    const label = action ? actionLabels[action] : toolName;
    // 添加状态后缀
    if (status === 'success') {
        return `${label} ✓`;
    }
    else if (status === 'failed') {
        return `${label} ✗`;
    }
    else if (status === 'pending_approval') {
        return `${label} (待审批)`;
    }
    return label;
}
/**
 * 将单个 NormalizedEntry 转换为 LogEntry
 */
export function normalizedEntryToLogEntry(entry) {
    switch (entry.entryType) {
        case 'user_message':
        case 'user_feedback':
            return {
                id: entry.id,
                type: LogType.User,
                content: entry.content,
            };
        case 'assistant_message':
            return {
                id: entry.id,
                type: LogType.Assistant,
                content: entry.content,
            };
        case 'next_action':
            return {
                id: entry.id,
                type: LogType.Action,
                content: entry.content,
            };
        case 'thinking':
            return {
                id: entry.id,
                type: LogType.Info,
                title: 'Thinking',
                content: entry.content,
            };
        case 'tool_use':
            return {
                id: entry.id,
                type: LogType.Tool,
                title: getToolTitle(entry),
                content: entry.content,
                isCollapsed: entry.metadata?.status === 'success',
                tool: {
                    action: entry.metadata?.action,
                    name: entry.metadata?.toolName,
                    id: entry.metadata?.toolId,
                    status: entry.metadata?.status,
                },
            };
        case 'error_message':
            return {
                id: entry.id,
                type: LogType.Error,
                content: entry.content,
            };
        case 'system_message':
            return {
                id: entry.id,
                type: LogType.Info,
                content: entry.content,
            };
        case 'loading':
            // loading 状态可以用 Cursor 表示
            return {
                id: entry.id,
                type: LogType.Cursor,
                content: '',
            };
        case 'token_usage_info':
            // token 使用信息 — 传递结构化数据供前端展示
            if (entry.metadata?.tokenUsage) {
                const { totalTokens = 0, modelContextWindow } = entry.metadata.tokenUsage;
                return {
                    id: entry.id,
                    type: LogType.Info,
                    content: entry.content,
                    tokenUsage: {
                        totalTokens,
                        modelContextWindow,
                    },
                };
            }
            return null;
        default:
            return null;
    }
}
/**
 * 批量转换 NormalizedEntry 数组为 LogEntry 数组
 */
export function normalizedEntriesToLogEntries(entries) {
    return entries
        .map(normalizedEntryToLogEntry)
        .filter((entry) => entry !== null);
}
/**
 * 创建一个 loading cursor entry
 */
export function createCursorEntry() {
    return {
        id: `cursor-${Date.now()}`,
        type: LogType.Cursor,
        content: '',
    };
}
//# sourceMappingURL=log-adapter.js.map