UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

138 lines (137 loc) 5.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.GoogleApiToolSet = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const GoogleApiTool_1 = require("./GoogleApiTool"); const GoogleApiToOpenApiConverter_1 = require("./GoogleApiToOpenApiConverter"); /** * GoogleApiToolSet class * Manages a set of GoogleApiTool instances for interacting with Google APIs */ class GoogleApiToolSet { /** * Create a new GoogleApiToolSet * @param tools The underlying RestApiTool instances to wrap */ constructor(tools) { this.tools = tools.map(tool => new GoogleApiTool_1.GoogleApiTool(tool)); } /** * Get all tools in the toolset * @returns All GoogleApiTool instances in this toolset */ getTools() { return this.tools; } /** * Get a tool by name * @param toolName The name of the tool to find * @returns The matching GoogleApiTool or undefined if not found */ getTool(toolName) { return this.tools.find(tool => tool.name === toolName); } /** * Configure authentication for all tools in the toolset * @param clientId The OAuth2 client ID * @param clientSecret The OAuth2 client secret */ configureAuth(clientId, clientSecret) { for (const tool of this.tools) { tool.configureAuth(clientId, clientSecret); } } /** * Load a toolset for a specific Google API * * @param apiName The name of the Google API * @param apiVersion The version of the Google API * @returns A new GoogleApiToolSet for the specified API */ static async loadToolSet(apiName, apiVersion) { console.log(`Loading tool set for Google API: ${apiName} v${apiVersion}`); try { // Use the GoogleApiToOpenApiConverterImpl to convert the Google API to OpenAPI const converter = new GoogleApiToOpenApiConverter_1.GoogleApiToOpenApiConverterImpl(apiName, apiVersion); const openApiSpec = await converter.convert(); // This is still a placeholder implementation // In a real implementation, we would use the openApiSpec to create an OpenAPIToolset console.log(`Converted ${apiName} API to OpenAPI format`); // Mock implementation that returns an empty toolset return new GoogleApiToolSet([]); } catch (error) { console.error(`Error loading tool set for ${apiName}:`, error); return new GoogleApiToolSet([]); } } /** * Load a tool set with OpenID Connect authentication * * Note: This is a placeholder implementation until the OpenAPIToolset is implemented * * @param specFile Path to an OpenAPI spec file * @param specDict OpenAPI spec as a dictionary * @param scopes OAuth2 scopes to request * @returns An OpenAPIToolset or undefined if not possible */ static _loadToolSetWithOidcAuth(specFile, specDict, scopes) { let specStr; // Load spec from file if provided if (specFile) { const callerDir = path.dirname(new Error().stack?.split('\n')[2]?.match(/at .+ \((.+):\d+:\d+\)/)?.[1] || ''); const yamlPath = path.join(callerDir, specFile); try { specStr = fs.readFileSync(yamlPath, 'utf-8'); } catch (error) { console.error(`Error reading spec file: ${yamlPath}`, error); return undefined; } } // Placeholder for OpenAPIToolset creation console.log('Creating OpenAPIToolset with OIDC auth'); console.log('Spec string available:', !!specStr); console.log('Spec dict available:', !!specDict); console.log('Scopes:', scopes); // Mock implementation that returns an empty toolset return { getTools: () => [] }; } } exports.GoogleApiToolSet = GoogleApiToolSet;