/** * Multi-type adapter architecture interfaces. * * Extends adapters to support subprocess, remote (HTTP/WebSocket), and * programmatic (SDK) adapter types beyond the original subprocess-only model. * * @see ../../../docs/18-multi-adapter-architecture.md */ import type { AgentName } from './types.js'; import type { AgentCapabilities, ModelCapabilities } from './capabilities.js'; import type { RunOptions } from './run-options.js'; import type { AgentEvent } from './events.js'; import type { InteractionResponse } from './interaction.js'; import type { AuthState, AuthSetupGuidance, AgentConfig, AgentConfigSchema, Session } from './adapter.js'; /** * Base interface shared across all adapter types. * Contains common functionality independent of execution method. */ export interface BaseAgentAdapterInterface { readonly agent: AgentName; readonly displayName: string; readonly adapterType: 'subprocess' | 'remote' | 'programmatic'; readonly minVersion?: string; readonly capabilities: AgentCapabilities; readonly models: ModelCapabilities[]; readonly defaultModelId?: string; readonly configSchema: AgentConfigSchema; detectAuth(): Promise; getAuthGuidance(): AuthSetupGuidance; sessionDir(cwd?: string): string; parseSessionFile(filePath: string): Promise; listSessionFiles(cwd?: string): Promise; readConfig(cwd?: string): Promise; writeConfig(config: Partial, cwd?: string): Promise; /** Optional adapter-native model discovery hook used by ModelRegistry.refresh(). */ discoverModels?(cwd?: string): Promise; /** Env-var names that indicate the current process is running under this harness. */ readonly hostEnvSignals?: readonly string[]; /** Extract adapter-specific metadata from an env snapshot. */ readHostMetadata?(env: NodeJS.ProcessEnv): Record; } import type { AgentAdapter as LegacyAgentAdapter } from './adapter.js'; /** * Subprocess-based adapter (traditional adapters model). * Spawns CLI process and parses line-based output. */ export interface SubprocessAdapter extends LegacyAgentAdapter { readonly adapterType: 'subprocess'; } /** * Remote adapter for HTTP APIs, WebSocket connections, or Unix sockets. * Manages persistent connections and may handle server lifecycle. */ export interface RemoteAdapter extends LegacyAgentAdapter { readonly adapterType: 'remote'; readonly connectionType: 'http' | 'websocket' | 'unix'; connect(options: RunOptions): Promise; disconnect(connection: RemoteConnection): Promise; startServer?(options?: ServerOptions): Promise; stopServer?(serverInfo: ServerInfo): Promise; healthCheck?(serverInfo: ServerInfo): Promise; } /** * Connection abstraction for remote adapters. */ export interface RemoteConnection { readonly connectionId: string; readonly connectionType: 'http' | 'websocket' | 'unix'; readonly endpoint: string; send(data: unknown): Promise; receive(): AsyncIterableIterator; close(): Promise; } /** * HTTP-specific connection with REST API methods. */ export interface HttpConnection extends RemoteConnection { readonly connectionType: 'http'; readonly baseUrl: string; get(path: string, params?: Record): Promise; post(path: string, data?: unknown): Promise; put(path: string, data?: unknown): Promise; delete(path: string): Promise; stream(path: string, data?: unknown): AsyncIterableIterator; } /** * WebSocket-specific connection with pub/sub capabilities. */ export interface WebSocketConnection extends RemoteConnection { readonly connectionType: 'websocket'; readonly websocketUrl: string; subscribe(channel: string): AsyncIterableIterator; unsubscribe(channel: string): Promise; send(message: WebSocketMessage): Promise; } export interface WebSocketMessage { type: string; channel?: string; data: unknown; } /** * Programmatic adapter for direct SDK integration. * No subprocess or network communication - direct function calls. */ export interface ProgrammaticRun extends AsyncIterableIterator { send?(text: string): Promise; respond?(interactionId: string, response: InteractionResponse): Promise; interrupt?(): Promise; close?(): Promise | void; } export interface ProgrammaticAdapter extends LegacyAgentAdapter { readonly adapterType: 'programmatic'; execute(options: RunOptions): ProgrammaticRun; } /** * Server configuration options for remote adapters. */ export interface ServerOptions { port?: number; host?: string; timeout?: number; env?: Record; args?: string[]; } /** * Information about a managed server instance. */ export interface ServerInfo { readonly serverId: string; readonly serverType: string; readonly endpoint: string; readonly pid?: number; readonly port: number; readonly startedAt: Date; } /** * Server health status. */ export interface ServerHealth { status: 'starting' | 'healthy' | 'unhealthy' | 'stopped'; uptime?: number; lastCheck: Date; details?: string; } /** * Server lifecycle manager interface. */ export interface ServerManager { start(adapter: RemoteAdapter, options?: ServerOptions): Promise; stop(serverId: string): Promise; health(serverId: string): Promise; list(): Promise; cleanup(): Promise; } /** * Union of all adapter types. This replaces the original AgentAdapter interface * while maintaining backward compatibility. */ export type AgentAdapter = SubprocessAdapter | RemoteAdapter | ProgrammaticAdapter; export declare function isSubprocessAdapter(adapter: AgentAdapter): adapter is SubprocessAdapter; export declare function isRemoteAdapter(adapter: AgentAdapter): adapter is RemoteAdapter; export declare function isProgrammaticAdapter(adapter: AgentAdapter): adapter is ProgrammaticAdapter; export declare function isHttpConnection(connection: RemoteConnection): connection is HttpConnection; export declare function isWebSocketConnection(connection: RemoteConnection): connection is WebSocketConnection;