/**
 * 轻量工具目录，只注册 schema 元数据，不管理工具实例。
 * 用于治理配置、运行时解析和 Prompt Builder 查询。
 */

export interface ToolSchema {
  name: string;
  toolset: string;
  description: string;
  visibility?: 'internal' | 'tool' | 'skill';
  capability?: 'text' | 'vision' | 'multimodal' | 'image_aigc';
  isCore?: boolean;
  canDisable?: boolean;
  supportsPromptHint?: boolean;
  requiresModel?: boolean;
}

const catalog = new Map<string, ToolSchema>();

export function registerSchema(schema: ToolSchema): void {
  catalog.set(schema.name, schema);
}

export function getAllToolSchemas(): ToolSchema[] {
  return [...catalog.values()];
}

export function getToolSchema(name: string): ToolSchema | undefined {
  return catalog.get(name);
}

export function getToolNamesByToolset(toolset: string): string[] {
  return [...catalog.values()]
    .filter(entry => entry.toolset === toolset)
    .map(entry => entry.name);
}

export function getToolNamesByToolsets(toolsets: string[]): string[] {
  return [...catalog.values()]
    .filter(entry => toolsets.includes(entry.toolset))
    .map(entry => entry.name);
}

/** 默认启用的工具集（所有 Agent 都有） */
export const TOOLSET_DEFAULTS = ['base', 'planning', 'interaction'] as const;
export const TOOLSET_VISION = 'vision' as const;
export const TOOLSET_DOCUMENT = 'document' as const;
export const TOOLSET_AIGC = 'aigc' as const;
export const TOOLSET_WEIXIN_DESKTOP = 'weixin_desktop' as const;
export const TOOLSET_MYSQL = 'mysql' as const;

// --- 集中注册入口，import 触发各工具文件的 registerSchema ---
import './builtin/bash.js';
import './builtin/file.js';
import './builtin/search.js';
import './builtin/edit.js';
import './builtin/patch.js';
import './builtin/clarify.js';
import './builtin/memory.js';
import './builtin/memory_types.js';
import './builtin/read_skill.js';
import './builtin/read_skill_file.js';
import './builtin/skill_manage.js';
import './builtin/delegate_task.js';
import './builtin/delegate_parallel.js';
import './builtin/escalate.js';
import './todo_tool.js';
import './builtin/image_recognize.js';
import './builtin/execute_skill.js';
import './builtin/text_to_image.js';
import './builtin/image_to_image.js';
import './builtin/weixin_send_text.js';
import './builtin/mysql.js';
