import { AnyAgentTool } from '../tools/common.js';

// --- 插件接口 ---

export interface NetaClawPluginDefinition {
  id: string;
  name: string;
  version: string;
  tools?: () => AnyAgentTool[];
}

// --- LLM 提供商接口 ---

export interface LLMMessage {
  role: 'system' | 'user' | 'assistant' | 'tool';
  content: string;
  toolCalls?: ToolCall[];
  toolCallId?: string;
}

/** 带数据库 ID 的消息，用于压缩流程定位 */
export interface LLMMessageWithId extends LLMMessage {
  /** 数据库自增 ID (来自 NetaClawMessageEntity.id) */
  id: number;
}

export interface ToolCall {
  id: string;
  name: string;
  arguments: string; // JSON string
}

export interface LLMResponse {
  content: string;
  toolCalls?: ToolCall[];
  thinking?: string;
  usage?: { inputTokens: number; outputTokens: number };
  stopReason?: 'end_turn' | 'tool_use' | 'max_tokens';
}

export type ThinkLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'adaptive';

export interface LLMProviderConfig {
  provider: string;
  model: string;
  apiKey: string;
  baseUrl?: string;
  channelId?: number;
  channelName?: string;
  channelSupplier?: string;
  temperature?: number;
  maxTokens?: number;
  thinkLevel?: ThinkLevel;
}

export interface LLMChatCallbacks {
  onTextDelta?: (text: string) => void;
  onThinkingDelta?: (text: string) => void;
}

export interface LLMProvider {
  id: string;
  name: string;
  chat(
    messages: LLMMessage[],
    tools: AnyAgentTool[],
    config: LLMProviderConfig,
    callbacks?: LLMChatCallbacks
  ): Promise<LLMResponse>;
}
