UNPKG

adk-typescript

Version:

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

80 lines (79 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthTool = void 0; const BaseTool_1 = require("../tools/BaseTool"); /** * Tool for handling authentication flows */ class AuthTool extends BaseTool_1.BaseTool { /** * Creates a new authentication tool * * @param options The options for the tool */ constructor(options) { super({ name: options.name || 'auth_tool', description: options.description || 'Tool for handling authentication flows', isLongRunning: true }); this.onAuthComplete = options.onAuthComplete; } /** * Get the function declaration for this tool * * @returns The function declaration */ _getDeclaration() { return { name: this.name, description: this.description, parameters: { type: 'object', properties: { authScheme: { type: 'string', description: 'The authentication scheme to use' }, credentials: { type: 'object', description: 'The credentials for authentication' } }, required: ['authScheme'] } }; } /** * Execute the authentication tool * * @param params The parameters for tool execution * @param context The context for tool execution * @returns The result of the tool execution */ async execute(params, context) { const contextValue = context.get('functionCallId'); const functionCallId = typeof contextValue === 'string' ? contextValue : String(contextValue || ''); const authScheme = params.authScheme; const credentials = params.credentials || {}; // Create auth config const authConfig = { authScheme: authScheme, rawAuthCredential: credentials }; // Create auth tool arguments const authToolArgs = { functionCallId, authConfig }; // Call the auth complete handler if provided if (this.onAuthComplete) { await this.onAuthComplete(authToolArgs); } return { status: 'authentication_completed', authScheme }; } } exports.AuthTool = AuthTool;