/**
 * AI 配置接口
 */
export interface AIConfig {
    enabled: boolean;
    apiKey: string;
    baseUrl: string;
    model: string;
    maxTokens?: number;
    temperature?: number;
}
/**
 * 对话消息接口（支持 tool calling）
 */
export interface ChatMessage {
    role: 'system' | 'user' | 'assistant' | 'tool';
    content: string | null;
    tool_calls?: ToolCall[];
    tool_call_id?: string;
    name?: string;
}
/**
 * 工具调用接口（OpenAI function calling 格式）
 */
export interface ToolCall {
    id: string;
    type: 'function';
    function: {
        name: string;
        arguments: string;
    };
}
/**
 * Agent 事件类型
 */
export type AgentEventType = 'thinking' | 'message' | 'tool_call' | 'tool_result' | 'done' | 'error' | 'system_info';
/**
 * Agent 事件
 */
export interface AgentEvent {
    type: AgentEventType;
    content?: string;
    tool?: string;
    args?: any;
    result?: string;
    error?: string;
}
/** Agent 事件回调 */
export type AgentEventCallback = (event: AgentEvent) => void;
/**
 * 工具定义（OpenAI tools 格式）
 */
export interface ToolDefinition {
    type: 'function';
    function: {
        name: string;
        description: string;
        parameters: object;
    };
}
/** 工具执行器 */
export type ToolExecutor = (args: any, sessionId: string) => Promise<string>;
/** 前端显示消息（持久化用） */
export interface DisplayMessage {
    role: 'user' | 'assistant';
    content: string;
    skillName?: string;
    isSystemInfo?: boolean;
    agentSteps?: DisplayAgentStep[];
}
export interface DisplayAgentStep {
    type: 'tool_call' | 'tool_result';
    tool?: string;
    args?: any;
    result?: string;
    collapsed?: boolean;
}
/** 历史文件元数据 */
export interface HistoryMeta {
    sessionId: string;
    sessionName?: string;
    savedAt: number;
    messageCount: number;
    preview: string;
}
interface ISSHService {
    writeData(sessionId: string, data: string | Buffer): boolean;
    captureOutput(sessionId: string, timeoutMs?: number): Promise<string>;
    getSession(sessionId: string): any;
    getSystemContext(sessionId: string): Promise<string>;
}
interface ISkillService {
    getSkill(id: string): {
        name: string;
        content: string;
    } | undefined;
}
/**
 * AI Agent 服务 - 支持工具调用和自主操作终端
 */
export declare class AIService {
    private configDir;
    private configPath;
    private config;
    private historyDir;
    private chatHistories;
    private agentStates;
    private toolRegistry;
    private sshService?;
    private skillService?;
    private readonly MAX_HISTORY_AGE;
    private readonly MAX_MESSAGES;
    private readonly MAX_AGENT_ITERATIONS;
    private readonly AGENT_SYSTEM_PROMPT;
    constructor(sshService?: ISSHService, skillService?: ISkillService);
    private getDefaultConfig;
    private loadConfig;
    private saveConfig;
    private cleanupOldHistories;
    getConfig(): AIConfig;
    getFullConfig(): AIConfig;
    updateConfig(updates: Partial<AIConfig>): AIConfig;
    testConfig(config?: Partial<AIConfig>): Promise<{
        success: boolean;
        message: string;
    }>;
    /**
     * 注册工具
     */
    registerTool(name: string, definition: ToolDefinition, executor: ToolExecutor): void;
    /**
     * 获取所有工具定义（OpenAI tools 格式）
     */
    getToolDefinitions(): ToolDefinition[];
    /**
     * 注册内置工具
     */
    private registerBuiltinTools;
    /**
     * 检测会话是否为 Windows 环境
     */
    private isWindowsSession;
    /**
     * 危险命令拦截：将 rm/Remove-Item 转换为移动到回收站，阻止极端破坏性操作
     */
    private sanitizeCommand;
    /**
     * Unix (Linux/macOS) 命令安全检查
     */
    private sanitizeUnixCommand;
    /**
     * Windows (PowerShell) 命令安全检查
     */
    private sanitizeWindowsCommand;
    /**
     * 执行命令并捕获输出
     */
    private executeCommand;
    /**
     * 读取终端当前输出
     */
    private readTerminal;
    private getOrCreateHistory;
    private addMessage;
    clearHistory(sessionId: string): void;
    getHistory(sessionId: string): ChatMessage[] | null;
    /**
     * 保存前端显示消息到文件（含元数据）
     */
    saveDisplayHistory(sessionId: string, displayMessages: DisplayMessage[], sessionName?: string): void;
    /**
     * 加载前端显示消息（兼容新旧格式）
     */
    loadDisplayHistory(sessionId: string): DisplayMessage[] | null;
    /**
     * 列出所有历史对话（仅元数据）
     */
    listDisplayHistories(): HistoryMeta[];
    /**
     * 删除持久化的对话历史
     */
    deleteDisplayHistoryFile(sessionId: string): void;
    /**
     * 获取会话的系统上下文（从 sshService 的 session 元数据获取）
     * 保证每次对话都带上系统环境信息
     */
    private getSessionContext;
    /**
     * 运行 Agent
     * Agent 循环：调用 LLM → 处理 tool_calls → 执行工具 → 反馈结果 → 重复直到完成
     */
    agentRun(sessionId: string, userMessage: string, context: string | undefined, eventCallback: AgentEventCallback, skillId?: string): Promise<void>;
    /**
     * 停止 Agent
     */
    stopAgent(sessionId: string): boolean;
    /**
     * 调用 OpenAI API（非流式，用于 Agent 循环）
     */
    private callLLM;
    chat(sessionId: string, userMessage: string, context?: string): Promise<string>;
    chatStream(sessionId: string, userMessage: string, context?: string): AsyncGenerator<string, void, unknown>;
}
export {};
//# sourceMappingURL=ai.service.d.ts.map