Files
gemini-cli/packages/server/src/tools/tool-registry.ts
Jaana Dogan ddaa21c750 Remove dead methods from ToolRegistry (#91)
* getToolSchemas is deprecated.
* listAvailableTools is now getAllTools.
2025-04-21 13:29:36 -07:00

54 lines
1.3 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { FunctionDeclaration } from '@google/genai';
import { Tool } from './tools.js';
export class ToolRegistry {
private tools: Map<string, Tool> = new Map();
/**
* Registers a tool definition.
* @param tool - The tool object containing schema and execution logic.
*/
registerTool(tool: Tool): void {
if (this.tools.has(tool.name)) {
// Decide on behavior: throw error, log warning, or allow overwrite
console.warn(
`Tool with name "${tool.name}" is already registered. Overwriting.`,
);
}
this.tools.set(tool.name, tool);
}
/**
* Retrieves the list of tool schemas (FunctionDeclaration array).
* Extracts the declarations from the ToolListUnion structure.
* @returns An array of FunctionDeclarations.
*/
getFunctionDeclarations(): FunctionDeclaration[] {
const declarations: FunctionDeclaration[] = [];
this.tools.forEach((tool) => {
declarations.push(tool.schema);
});
return declarations;
}
/**
* Returns an array of all registered tool instances.
*/
getAllTools(): Tool[] {
return Array.from(this.tools.values());
}
/**
* Get the definition of a specific tool.
*/
getTool(name: string): Tool | undefined {
return this.tools.get(name);
}
}