/** * Sources Service * * Manages loading, merging, and accessing plugin sources. * Supports both bundled (read-only) sources and user custom sources. * * Key behaviors: * - Bundled sources cannot be deleted, only disabled via UI * - User sources can override bundled source settings * - User can add new custom sources */ import type { SourceConfig } from '../types/source.js'; /** * Extended source config with bundled flag */ export interface ExtendedSourceConfig extends SourceConfig { /** Whether this source is bundled with the application (read-only) */ bundled?: boolean; /** Whether this source requires an API key */ requiresApiKey?: boolean; /** Environment variable name for API key */ apiKeyEnvVar?: string; } /** * User source override - can modify enabled state or provide API keys */ export interface UserSourceOverride { /** Source ID to override */ id: string; /** Override enabled state */ enabled?: boolean; /** API key for authenticated sources */ apiKey?: string; /** Additional settings */ settings?: Record; } /** * User sources configuration file structure */ export interface UserSourcesConfig { version: string; description?: string; /** Overrides for bundled sources (can only disable, not delete) */ overrides: UserSourceOverride[]; /** Custom user-defined sources */ customSources: SourceConfig[]; } /** * Sources Service class */ export declare class SourcesService { private bundledSources; private userOverrides; private customSources; private mergedSources; private loaded; private bundledPath; private userPath; constructor(bundledPath?: string, userPath?: string); /** * Load sources from bundled and user files */ load(): boolean; /** * Load bundled sources from the defaults file */ private loadBundledSources; /** * Load user sources from the user config file. * * Uses Zod schema validation per Phase 3 audit (P0 #8) — caps string * lengths on URLs, API keys, and other user-supplied fields. Validation * failure leaves both arrays empty rather than crashing. */ private loadUserSources; /** * Merge bundled and user sources * User overrides are applied to bundled sources * Custom sources are appended at the end */ private mergeSources; /** * Get default fallback sources */ private getDefaultSources; /** * Check if service is loaded */ isLoaded(): boolean; /** * Get all merged sources */ getAll(): ExtendedSourceConfig[]; /** * Get only enabled sources */ getEnabled(): ExtendedSourceConfig[]; /** * Get source by ID */ getById(id: string): ExtendedSourceConfig | undefined; /** * Get sources by type */ getByType(type: string): ExtendedSourceConfig[]; /** * Check if a source is bundled (cannot be deleted) */ isBundled(id: string): boolean; /** * Disable a bundled source via UI * This saves an override to the user config * * @internal Should only be called from UI components */ disableSource(id: string): boolean; /** * Enable a source via UI * * @internal Should only be called from UI components */ enableSource(id: string): boolean; /** * Set the enabled state of a source * * @internal Should only be called from UI components */ setSourceEnabled(id: string, enabled: boolean): boolean; /** * Set API key for a source * * @internal Should only be called from UI components */ setSourceApiKey(id: string, apiKey: string): boolean; /** * Add a custom source * * @internal Should only be called from UI components */ addCustomSource(source: SourceConfig): boolean; /** * Remove a custom source (cannot remove bundled sources) * * @internal Should only be called from UI components */ removeCustomSource(id: string): boolean; /** * Update a custom source * * @internal Should only be called from UI components */ updateCustomSource(id: string, updates: Partial): boolean; /** * Save user configuration to file. Throws on I/O failure. */ private saveUserConfig; /** Attempt to persist user config; logs and returns false on failure. */ private trySave; /** * Reset user overrides to defaults * * @internal Should only be called from UI components */ resetOverrides(): boolean; /** * Get statistics about sources */ getStats(): { total: number; enabled: number; bundled: number; custom: number; }; } /** * Get the singleton sources service */ export declare function getSourcesService(): SourcesService; /** * Create a new sources service (for testing) */ export declare function createSourcesService(bundledPath?: string, userPath?: string): SourcesService; /** * Reset the singleton instance (for testing) */ export declare function resetSourcesService(): void; //# sourceMappingURL=sources-service.d.ts.map