/** * Tool Gateway — Remote managed tool provider pattern. * * Inspired by Hermes Agent v0.10's Tool Gateway feature. * Allows agents to access remote tool services (web search, image gen, TTS, * browser automation) through a unified gateway, removing the need for * individual API keys per tool. * * Key features: * - Subscription-based tool access (single API key → multiple tools) * - Per-tool opt-in/opt-out via configuration * - Auto-detection of gateway availability * - Fallback to direct API keys when gateway unavailable * - Usage tracking and quota enforcement * * Usage: * const gw = new ToolGateway({ endpoint: 'https://tools.example.com', apiKey: '...' }); * await gw.connect(); * const result = await gw.invoke('web-search', { query: 'hello' }); */ import { EventEmitter } from 'events'; export interface ToolGatewayConfig { /** Gateway endpoint URL */ endpoint: string; /** API key / subscription token for the gateway */ apiKey: string; /** Tools to enable (empty = all available) */ enabledTools?: string[]; /** Timeout for gateway calls (ms, default 60s) */ timeout?: number; /** Whether to prefer gateway over direct API keys */ preferGateway?: boolean; /** Retry config */ retry?: { maxRetries?: number; backoffMs?: number; }; } export interface GatewayTool { id: string; name: string; description: string; inputSchema: Record; category: 'search' | 'generation' | 'browser' | 'tts' | 'utility' | string; quotaRemaining?: number; available: boolean; } export interface GatewayInvocation { toolId: string; input: Record; requestId?: string; } export interface GatewayResult { toolId: string; requestId: string; status: 'success' | 'error' | 'quota_exceeded' | 'unavailable'; output?: unknown; error?: string; durationMs: number; quotaRemaining?: number; } export interface GatewayStatus { connected: boolean; endpoint: string; tools: GatewayTool[]; subscription?: { tier: string; quotaUsed: number; quotaTotal: number; resetAt?: string; }; } export declare class ToolGateway extends EventEmitter { private config; private tools; private connected; private logger; private invocationCount; constructor(config: ToolGatewayConfig); /** Connect to gateway and discover available tools */ connect(): Promise; /** Invoke a tool through the gateway */ invoke(toolId: string, input: Record): Promise; /** Get a tool definition (for MCP/tool schema exposure) */ getTool(toolId: string): GatewayTool | undefined; /** List all available tools */ listTools(): GatewayTool[]; /** Get current status */ getStatus(): GatewayStatus; /** Check if gateway should be preferred over direct API call */ shouldUseGateway(toolId: string): boolean; /** Disconnect from gateway */ disconnect(): void; get isConnected(): boolean; get totalInvocations(): number; private request; private generateRequestId; } export declare class ToolGatewayRegistry { private gateways; private toolToGateway; private logger; /** Register a gateway */ register(name: string, gateway: ToolGateway): void; /** Find which gateway provides a tool */ findGateway(toolId: string): ToolGateway | undefined; /** Invoke a tool, auto-routing to the right gateway */ invoke(toolId: string, input: Record): Promise; /** List all tools across all gateways */ listAllTools(): Array; /** Disconnect all gateways */ disconnectAll(): void; } //# sourceMappingURL=gateway-registry.d.ts.map