UNPKG

nestjs-a2a

Version:

NestJS module for creating Google Agent to Agent Server

84 lines (83 loc) 3.06 kB
import { ModuleRef } from '@nestjs/core'; import { Response } from 'express'; import { Request } from 'express'; import { AgentToAgentModuleOptions } from '../interfaces/a2a.options'; import { CancelTaskRequest, GetTaskPushNotificationRequest, GetTaskRequest, JSONRPCResponse, SendTaskRequest, SendTaskStreamingRequest, TaskResubscriptionRequest } from '../interfaces/a2a.types'; import { A2ARegistry } from './a2a.registry'; /** * Implements the A2A executor for handling A2A protocol requests in NestJS. */ export declare class A2AExecutor { private readonly options; private readonly request; private readonly registry; readonly moduleRef: ModuleRef; private readonly logger; private readonly taskStore; private readonly activeCancellations; constructor(options: AgentToAgentModuleOptions, request: Request, registry: A2ARegistry, moduleRef: ModuleRef); /** * Handles a task send request (non-streaming). */ handleTaskSend(body: SendTaskRequest): Promise<JSONRPCResponse>; /** * Handles a task send request with streaming response. */ handleTaskSendSubscribe(body: SendTaskStreamingRequest, response: Response): Promise<void>; /** * Handles a task get request. */ handleTaskGet(body: GetTaskRequest): Promise<JSONRPCResponse>; /** * Handles a task cancel request. */ handleTaskCancel(body: CancelTaskRequest): Promise<JSONRPCResponse>; /** * Handles a task resubscribe request. * Not fully implemented yet - returns unsupported operation error. */ handleTaskResubscribe(_body: TaskResubscriptionRequest): Promise<JSONRPCResponse>; /** * Handles a task get push notification request. * Not fully implemented yet - returns unsupported operation error. */ handleTaskGetPushNotification(_body: GetTaskPushNotificationRequest): Promise<JSONRPCResponse>; /** * Loads an existing task or creates a new one with the given message. */ private loadOrCreateTaskAndHistory; /** * Creates a task context object for the handler. */ private createTaskContext; /** * Finds an appropriate handler for the given task and message. * Currently just returns a default handler, but could be enhanced to select * based on task type, message content, etc. */ private findHandlerForTask; /** * Validates the parameters for a task send request. */ private validateTaskSendParams; /** * Helper to apply updates (status or artifact) immutably to a task and history. */ private applyUpdateToTaskAndHistory; /** * Type guard to check if an update is a task status update. */ private isTaskStatusUpdate; /** * Creates a TaskStatusUpdateEvent object. */ private createTaskStatusEvent; /** * Gets the current timestamp in ISO format. */ private getCurrentTimestamp; /** * Handles errors by converting them to appropriate JSON-RPC responses. */ private handleError; }