UNPKG

adk-typescript

Version:

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

125 lines (124 loc) 3.77 kB
import { BaseTool } from '../../BaseTool'; import { ToolContext } from '../../ToolContext'; import { ApiParameter, OperationEndpoint, Schema } from '../common/common'; import { ParsedOperation } from './OpenApiSpecParser'; import { AuthCredential, AuthScheme } from '../auth/AuthTypes'; /** * Converts a snake_case string to a lowerCamelCase string * @param snakeCaseString The input snake_case string * @returns The lowerCamelCase string */ export declare function snakeToLowerCamel(snakeCaseString: string): string; /** * Normalizes a JSON Schema type into a Gemini Schema type and checks if it's nullable * @param jsonSchemaType The JSON Schema type (string or array of strings) * @returns A tuple of [normalizedType, isNullable] */ export declare function normalizeJsonSchemaType(jsonSchemaType: string | string[] | null | undefined): [string | null, boolean]; /** * Converts an OpenAPI schema to a Gemini Schema * @param openApiSchema The OpenAPI schema object * @returns A Gemini Schema object */ export declare function toGeminiSchema(openApiSchema: Schema | null | undefined): any; /** * Authentication preparation state */ export type AuthPreparationState = 'pending' | 'done'; /** * RestApiTool options */ export interface RestApiToolOptions { name: string; description: string; endpoint: OperationEndpoint | string; operation: any; authScheme?: AuthScheme; authCredential?: AuthCredential; shouldParseOperation?: boolean; } /** * A generic tool that interacts with a REST API */ export declare class RestApiTool extends BaseTool { /** * The name of the tool */ name: string; /** * The description of the tool */ description: string; /** * The endpoint information for the REST API */ endpoint: OperationEndpoint; /** * The OpenAPI operation object */ operation: any; /** * The authentication scheme for the API */ authScheme?: AuthScheme; /** * The authentication credential for the API */ authCredential?: AuthCredential; /** * Parameters for the API call */ parameters: ApiParameter[]; /** * Return value from the API call */ returnValue?: ApiParameter; /** * Create a new RestApiTool * @param options Options for the REST API tool */ constructor(options: RestApiToolOptions); /** * Create a RestApiTool from a ParsedOperation * @param parsed The parsed operation * @returns A new RestApiTool */ static fromParsedOperation(parsed: ParsedOperation): RestApiTool; /** * Parse the operation to extract parameters and return value */ private _parseOperation; /** * Get the function declaration for the LLM * @returns The function declaration */ protected _getDeclaration(): any; /** * Configure the authentication scheme * @param authScheme The authentication scheme */ configureAuthScheme(authScheme: AuthScheme): void; /** * Configure the authentication credential * @param authCredential The authentication credential */ configureAuthCredential(authCredential: AuthCredential): void; /** * Prepare request parameters for the API call * @param params The API parameters * @param args The function arguments * @returns The prepared request parameters */ private _prepareRequestParams; /** * Execute the tool * @param args The function arguments * @param context The tool context * @returns The API response */ execute(args: Record<string, any>, context: ToolContext): Promise<any>; /** * String representation of the tool */ toString(): string; }