/** * @license * Copyright 2025 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ import type { IControlContext } from '../ControlContext.js'; import type { ControlRequestPayload, ControlResponse } from '../../types.js'; /** * Registry interface for controllers to register/deregister pending requests */ export interface IPendingRequestRegistry { registerIncomingRequest(requestId: string, controller: string, abortController: AbortController, timeoutId: NodeJS.Timeout): void; deregisterIncomingRequest(requestId: string): void; registerOutgoingRequest(requestId: string, controller: string, resolve: (response: ControlResponse) => void, reject: (error: Error) => void, timeoutId: NodeJS.Timeout): void; deregisterOutgoingRequest(requestId: string): void; } /** * Abstract base controller class * * Subclasses should implement handleRequestPayload() to process specific * control request types. */ export declare abstract class BaseController { protected context: IControlContext; protected registry: IPendingRequestRegistry; protected controllerName: string; constructor(context: IControlContext, registry: IPendingRequestRegistry, controllerName: string); /** * Handle an incoming control request * * Manages lifecycle: register -> process -> deregister */ handleRequest(payload: ControlRequestPayload, requestId: string): Promise>; /** * Send an outgoing control request to SDK * * Manages lifecycle: register -> send -> wait for response -> deregister * Respects the provided AbortSignal for cancellation. */ sendControlRequest(payload: ControlRequestPayload, timeoutMs?: number, signal?: AbortSignal): Promise; /** * Abstract method: Handle specific request payload * * Subclasses must implement this to process their domain-specific requests. */ protected abstract handleRequestPayload(payload: ControlRequestPayload, signal: AbortSignal): Promise>; /** * Cleanup resources */ cleanup(): void; }