UNPKG

adk-typescript

Version:

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

95 lines (94 loc) 4.39 kB
/** * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BaseTool, FunctionDeclaration } from '../BaseTool'; import { ToolContext } from '../ToolContext'; import { RestApiTool } from '../openapi-tool/openapi-spec-parser/RestApiTool'; /** * A tool that wraps a RestApiTool to interact with a specific Application Integration endpoint. * * This tool adds Application Integration specific context like connection * details, entity, operation, and action to the underlying REST API call * handled by RestApiTool. It prepares the arguments and then delegates the * actual API call execution to the contained RestApiTool instance. * * * Generates request params and body * * Attaches auth credentials to API call. * * Example: * ``` * // Each API operation in the spec will be turned into its own tool * // Name of the tool is the operationId of that operation, in snake case * const operations = operationGenerator.parse(openApiSpecDict); * const tool = operations.map(op => RestApiTool.fromParsedOperation(op)); * ``` */ export declare class IntegrationConnectorTool extends BaseTool { /** Fields to exclude from the schema */ private static readonly EXCLUDE_FIELDS; /** Optional fields that should not be required */ private static readonly OPTIONAL_FIELDS; /** Name of the connection */ readonly connectionName: string; /** Host for the connection */ readonly connectionHost: string; /** Service name for the connection */ readonly connectionServiceName: string; /** Entity being targeted */ readonly entity: string; /** Operation being performed */ readonly operation: string; /** Action associated with the operation */ readonly action: string; /** The REST API tool that handles the underlying API communication */ private readonly restApiTool; /** * Initializes the IntegrationConnectorTool. * * @param name The name of the tool, typically derived from the API operation. * Should be unique and adhere to Gemini function naming conventions * (e.g., less than 64 characters). * @param description A description of what the tool does, usually based on the * API operation's summary or description. * @param connectionName The name of the Integration Connector connection. * @param connectionHost The hostname or IP address for the connection. * @param connectionServiceName The specific service name within the host. * @param entity The Integration Connector entity being targeted. * @param operation The specific operation being performed on the entity. * @param action The action associated with the operation (e.g., 'execute'). * @param restApiTool An initialized RestApiTool instance that handles the * underlying REST API communication based on an OpenAPI specification * operation. This tool will be called by IntegrationConnectorTool with * added connection and context arguments. */ constructor(name: string, description: string, connectionName: string, connectionHost: string, connectionServiceName: string, entity: string, operation: string, action: string, restApiTool: RestApiTool); /** * Returns the function declaration in the Gemini Schema format. * @returns The function declaration */ protected _getDeclaration(): FunctionDeclaration; /** * Executes the tool with the provided arguments. * @param args The arguments for the tool * @param context Context for the tool execution * @returns The result of the tool execution */ execute(args: Record<string, any>, context: ToolContext): Promise<any>; /** * Returns a string representation of the tool. * @returns A string representation */ toString(): string; }