import type { TaskHandle } from '../task/task-handle.js'; import type { Provider } from '../task/task-state.js'; import type { ProviderCapabilities } from './provider-capabilities.js'; /** * Options passed to `BaseProviderAdapter.spawn()` to start a provider session. */ export interface ProviderSpawnOptions { taskId: string; prompt: string; cwd: string; timeout: number; model?: string; effort?: 'low' | 'medium' | 'high' | 'xhigh'; developerInstructions?: string; } /** * Result of an availability check on a provider adapter. */ export type AvailabilityResult = { available: true; } | { available: false; reason: string; }; /** * Base class for all provider adapters. * * Implements the Template Method pattern: `spawn()` provides the common * lifecycle skeleton (abort controller, timeout, error handling) and * delegates the actual provider interaction to `executeSession()`. */ export declare abstract class BaseProviderAdapter { /** Unique provider identifier. */ abstract readonly id: Provider; /** Human-readable display name. */ abstract readonly displayName: string; /** Check whether the provider is currently available. */ abstract checkAvailability(): AvailabilityResult; /** Return the capability matrix for this provider. */ abstract getCapabilities(): ProviderCapabilities; /** Return runtime statistics for observability. */ abstract getStats(): Record; /** * Template Method hook — the actual provider session logic. * Subclasses implement this to drive the provider (spawn process, call API, etc.). */ protected abstract executeSession(handle: TaskHandle, prompt: string, signal: AbortSignal, options: ProviderSpawnOptions): Promise; /** * Spawn a provider session for the given task. * * Template method: checks terminal state, sets up AbortController + timeout, * calls `executeSession`, and handles errors. */ spawn(options: ProviderSpawnOptions, handle: TaskHandle): Promise; /** * Attempt to abort a running task by ID. * Default implementation returns false (not supported). */ abort(_taskId: string): Promise; /** * Graceful shutdown hook. Called when the server is stopping. * Default implementation is a no-op. */ shutdown(): Promise; }