const tools = [];

export function registerTool(definition) {
  const { id, name, desc, run } = definition || {};
  if (!id || !name || !run) {
    throw new Error("Tool definition must include id, name and run");
  }

  const existing = tools.findIndex(t => t.id === id);
  const tool = { ...definition };

  if (existing >= 0) {
    tools[existing] = tool;
  } else {
    tools.push(tool);
  }

  return tool;
}

export function getTools() {
  return [...tools];
}
