import { useState } from "react"; import type { Plugin, ToolPlugin } from "./types.js"; interface UseActiveToolResult { activePlugin: ToolPlugin | null; activateTool: (id: string) => void; deactivateTool: () => void; } /** Manages which tool plugin is currently active. */ export function useActiveTool(plugins: Plugin[]): UseActiveToolResult { let [activeId, setActiveId] = useState(null); let activePlugin = (plugins.find((p) => p.type === "tool" && p.id === activeId) ?? null) as ToolPlugin | null; return { activePlugin, activateTool: setActiveId, deactivateTool: () => setActiveId(null), }; }