// Copyright (C) 2026 Rob Colbert // Licensed under the Apache License, Version 2.0 import type { IAiTool } from "@gadget/ai"; export interface DroneToolboxEnvironment { NODE_ENV: string; services?: { google?: { cse?: { apiKey?: string; engineId?: string; }; }; }; workspace?: { workspaceDir?: string; projectDir?: string; cacheDir?: string; }; } export type ToolMap = Map; export type ToolSet = Set; export class AiToolbox { private _env: DroneToolboxEnvironment; private tools: ToolMap = new Map(); private modeSets: Map = new Map>(); constructor(env: DroneToolboxEnvironment) { this._env = env; } get env(): DroneToolboxEnvironment { return this._env; } updateWorkspace(workspace: NonNullable): void { this._env.workspace = workspace; } register(tool: IAiTool, modes?: string[]): void { if (this.tools.has(tool.name)) { throw new Error(`tool already registered: ${tool.name}`); } this.tools.set(tool.name, tool); if (!modes) { return; } for (const mode of modes) { let set = this.modeSets.get(mode); if (!set) { set = new Set(); this.modeSets.set(mode, set); } set.add(tool); } } getTool(name: string): IAiTool | undefined { return this.tools.get(name); } getModeSet(mode: string): ToolSet | undefined { return this.modeSets.get(mode); } getToolNamesForMode(mode: string): string[] { return Array.from(this.getModeSet(mode) || []).map((tool) => tool.name); } }