/**
 * Provider RPC handlers — scanning + model fetching.
 */

import { scanAllProviders } from '../provider-scanner.ts';
import { fetchModelsForProvider } from '../model-fetcher.ts';

export function createProviderHandlers() {
  return {
    'provider.scan': async () => {
      try {
        const providers = await scanAllProviders();
        return { providers };
      } catch (err) {
        console.error('[provider.scan]', err);
        return { providers: [] };
      }
    },

    'provider.models': async ({ provider }: { provider: string }) => {
      try {
        const models = await fetchModelsForProvider(provider);
        return { models };
      } catch (err) {
        console.error('[provider.models]', err);
        return { models: [] };
      }
    },
  };
}
