feat: unified error handling + AI service modularisation
Error handling (Prompt 2): - src/services/errors.ts: AppError class, normalizeError(), throwServiceError() helper - 6 services wrapped with try/catch (property, match, need, shortlist, futureSignal, inquiry) - inquiryService aligned from custom ServiceResult<T> to standard ServiceResponse types - Results, MatchCenter, FutureAvailability pages show <ErrorState onRetry> on query failure AI modularisation (Prompt 3): - src/services/aiService.ts reduced from 755 → 19 lines (barrel re-export) - src/services/ai/IAIService.ts: typed interface + all response types - src/services/ai/mock/: needParser, compareBuilder, decisionBrief, listingParser, MockAIService - src/services/ai/openrouter/OpenRouterAIService.ts: model-agnostic skeleton - src/services/ai/prompts/: 4 prompt template files (needParsing, matchExplanation, compareSummary, decisionBrief) - src/services/ai/index.ts: factory selects Mock or OpenRouter via VITE_USE_REAL_AI flag - All existing import paths unchanged — zero call-site modifications Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* AI Service Factory
|
||||
*
|
||||
* Selects the active implementation based on the VITE_USE_REAL_AI feature flag.
|
||||
*
|
||||
* Mock mode (default): no API key required, all responses are deterministic.
|
||||
* Real mode: set VITE_USE_REAL_AI=true + VITE_OPENROUTER_API_KEY in .env
|
||||
*/
|
||||
import { MockAIService } from './mock/MockAIService'
|
||||
import { OpenRouterAIService } from './openrouter/OpenRouterAIService'
|
||||
import type { IAIService } from './IAIService'
|
||||
|
||||
const useRealAI = import.meta.env.VITE_USE_REAL_AI === 'true'
|
||||
&& !!import.meta.env.VITE_OPENROUTER_API_KEY
|
||||
|
||||
export const aiService: IAIService = useRealAI ? OpenRouterAIService : MockAIService
|
||||
|
||||
// Named export so callers can reach the concrete impl when needed
|
||||
export { MockAIService, OpenRouterAIService }
|
||||
export type { IAIService }
|
||||
Reference in New Issue
Block a user