summaryrefslogtreecommitdiff
path: root/packages/cli/src/tools/tool-registry.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-04-17 18:06:21 -0400
committerN. Taylor Mullen <[email protected]>2025-04-17 15:29:34 -0700
commitcfc697a96d2e716a75e1c3b7f0f34fce81abaf1e (patch)
treee06bcba67ca71a874048aa887b17457dbd409bdf /packages/cli/src/tools/tool-registry.ts
parent7928c1727f0b208ed34850cc89bbb36ea3dd23e5 (diff)
Run `npm run format`
- Also updated README.md accordingly. Part of https://b.corp.google.com/issues/411384603
Diffstat (limited to 'packages/cli/src/tools/tool-registry.ts')
-rw-r--r--packages/cli/src/tools/tool-registry.ts88
1 files changed, 45 insertions, 43 deletions
diff --git a/packages/cli/src/tools/tool-registry.ts b/packages/cli/src/tools/tool-registry.ts
index 48030397..a27d09b9 100644
--- a/packages/cli/src/tools/tool-registry.ts
+++ b/packages/cli/src/tools/tool-registry.ts
@@ -2,56 +2,58 @@ import { ToolListUnion, FunctionDeclaration } from '@google/genai';
import { Tool } from './tools.js';
class ToolRegistry {
- private tools: Map<string, Tool> = new Map();
+ 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);
+ /**
+ * 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 in the format required by Gemini.
- * @returns A ToolListUnion containing the function declarations.
- */
- getToolSchemas(): ToolListUnion {
- const declarations: FunctionDeclaration[] = [];
- this.tools.forEach(tool => {
- declarations.push(tool.schema);
- });
+ /**
+ * Retrieves the list of tool schemas in the format required by Gemini.
+ * @returns A ToolListUnion containing the function declarations.
+ */
+ getToolSchemas(): ToolListUnion {
+ const declarations: FunctionDeclaration[] = [];
+ this.tools.forEach((tool) => {
+ declarations.push(tool.schema);
+ });
- // Return Gemini's expected format. Handle the case of no tools.
- if (declarations.length === 0) {
- // Depending on the SDK version, you might need `undefined`, `[]`, or `[{ functionDeclarations: [] }]`
- // Check the documentation for your @google/genai version.
- // Let's assume an empty array works or signifies no tools.
- return [];
- // Or if it requires the structure:
- // return [{ functionDeclarations: [] }];
- }
- return [{ functionDeclarations: declarations }];
+ // Return Gemini's expected format. Handle the case of no tools.
+ if (declarations.length === 0) {
+ // Depending on the SDK version, you might need `undefined`, `[]`, or `[{ functionDeclarations: [] }]`
+ // Check the documentation for your @google/genai version.
+ // Let's assume an empty array works or signifies no tools.
+ return [];
+ // Or if it requires the structure:
+ // return [{ functionDeclarations: [] }];
}
+ return [{ functionDeclarations: declarations }];
+ }
- /**
- * Optional: Get a list of registered tool names.
- */
- listAvailableTools(): string[] {
- return Array.from(this.tools.keys());
- }
+ /**
+ * Optional: Get a list of registered tool names.
+ */
+ listAvailableTools(): string[] {
+ return Array.from(this.tools.keys());
+ }
- /**
- * Get the definition of a specific tool.
- */
- getTool(name: string): Tool | undefined {
- return this.tools.get(name);
- }
+ /**
+ * Get the definition of a specific tool.
+ */
+ getTool(name: string): Tool | undefined {
+ return this.tools.get(name);
+ }
}
// Export a singleton instance of the registry
-export const toolRegistry = new ToolRegistry(); \ No newline at end of file
+export const toolRegistry = new ToolRegistry();