/** * @name premium/provider-bridge * @description Dynamic loader and connection manager for premium provider adapters. * * Provider adapters live in the private subrepo (`sap-mcp-premium-private/providers/`). * The public server loads them dynamically only when `SAP_MCP_ENABLE_PREMIUM_PLUGINS=true` * and the corresponding provider env vars are configured. * * The bridge maintains a registry of active adapters keyed by `pluginId:capabilityId`, * handles connect/disconnect lifecycle, and exposes health status to the metrics * and monitoring layer. * * Security: adapters are loaded from the configured `SAP_MCP_PLUGIN_DIR` only. * No code is ever loaded from MCP tool input or user-supplied JSON. * * @flow * 1. `stream-broker.ts` / `webhook-engine.ts` need events for a capability. * 2. → `getProviderAdapter(pluginId, capabilityId)` returns the adapter. * 3. If not loaded, `loadProviderAdapter()` dynamically imports from the * private subrepo providers directory. * 4. Adapter `connect()` is called once, then `subscribe()` returns an * async iterable of events. * 5. `disconnectAllProviders()` is called on graceful shutdown. * * @module premium/provider-bridge */ import type { PremiumProviderAdapter, ProviderEvent, ProviderHealth } from './types.js'; /** * @name loadProviderAdapter * @description Dynamically load a provider adapter from the private subrepo. * * The adapter module must be located at: * `/providers//.js` * (or `.ts` if running via tsx/ts-node). * * The module must export a default factory function that returns a * `PremiumProviderAdapter`: * * ```ts * export default function createAdapter(): PremiumProviderAdapter { ... } * ``` * * @param pluginId - The premium plugin id. * @param capabilityId - The capability id within the plugin. * @returns The loaded and connected `PremiumProviderAdapter`, or `null` if * private plugins are disabled, the dir is not configured, or the module * is not found. * * @usedBy `getProviderAdapter` */ export declare function loadProviderAdapter(pluginId: string, capabilityId: string): Promise; /** * @name getProviderAdapter * @description Get or load a provider adapter for a plugin/capability pair. * * If the adapter is already in the registry, returns it directly. * Otherwise, attempts to load it from the private subrepo. * * @param pluginId - The premium plugin id. * @param capabilityId - The capability id within the plugin. * @returns The `PremiumProviderAdapter`, or `null` if not available. * * @usedBy `stream-broker.ts`, `webhook-engine.ts` */ export declare function getProviderAdapter(pluginId: string, capabilityId: string): Promise; /** * @name getProviderHealth * @description Get health status for a specific provider adapter. * * @param pluginId - The premium plugin id. * @param capabilityId - The capability id within the plugin. * @returns `ProviderHealth` if the adapter is loaded, otherwise a default unhealthy status. * * @usedBy `metrics.ts` */ export declare function getProviderHealth(pluginId: string, capabilityId: string): Promise; /** * @name getAllProviderHealth * @description Get health status for all configured provider adapters. * * Proactively attempts to load every capability whose `providerEnv` vars are * all set, then reports health for each. Capabilities that fail to load get * an unhealthy entry with the failure reason in `lastError`. * * This ensures `providerHealth` is never `{}` when providers are configured — * the agent can always see WHY a provider is not loading. * * @returns Record keyed by `pluginId:capabilityId` → `ProviderHealth`. * * @usedBy `metrics.ts` */ export declare function getAllProviderHealth(): Promise>; /** * @name subscribeToProvider * @description Subscribe to events from a provider adapter with filters. * * Convenience wrapper that loads the adapter and returns the async iterable. * * @param pluginId - The premium plugin id. * @param capabilityId - The capability id within the plugin. * @param filters — Filter object passed to the adapter's `subscribe()`. * @returns Async iterable of `ProviderEvent`, or `null` if the adapter is not available. * * @usedBy `stream-broker.ts`, `webhook-engine.ts` */ export declare function subscribeToProvider(pluginId: string, capabilityId: string, filters: Record): Promise | null>; /** * @name disconnectAllProviders * @description Disconnect all loaded provider adapters gracefully. * * Called during server shutdown to clean up connections. * * @usedBy `remote/server.ts` shutdown handler */ export declare function disconnectAllProviders(): Promise; /** * @name preloadPremiumProviders * @description Eagerly load and connect all configured provider adapters at startup. * * Called by the remote server during `start()` — before the HTTP listener * accepts requests. This ensures providers are running when the first agent * session arrives, eliminates cold-start latency, and surfaces configuration * errors immediately in the startup logs. * * Iterates every capability that requires a provider, checks env readiness, * and attempts to load + connect each adapter. Failures are logged but do not * block server startup — the server starts regardless, and `providerHealth` * will report the failure reason when queried. * * @usedBy `remote/server.ts:start()` — after premium memory manager init. */ export declare function preloadPremiumProviders(): Promise; //# sourceMappingURL=provider-bridge.d.ts.map