7.1 KiB
7.1 KiB
Research API Separation of Concerns
Date: 2025-01-29
Status: Completed
Overview
Properly separated Research API types from Blog Writer API to ensure clean separation of concerns. Research components now use dedicated researchApi.ts instead of blogWriterApi.ts.
Problem
Research components were importing types from blogWriterApi.ts, which violated separation of concerns:
- Research is a standalone engine used by multiple tools (Blog Writer, Podcast Maker, YouTube Creator, etc.)
- Mixing research types with blog writer types created confusion and tight coupling
- Made it difficult to maintain and extend research functionality independently
Solution
Created Dedicated Research API File
frontend/src/services/researchApi.ts - New dedicated file containing:
ResearchMode- Research depth levelsResearchProvider- Provider types (google, exa, tavily)SourceType- Source categoriesDateRange- Date filter optionsResearchSource- Source data structureResearchConfig- Complete research configuration (Exa, Tavily options)ResearchResponse- Generic research response interfaceResearchRequest- Research request interface
Updated All Research Components
All Research components now import from researchApi.ts:
Updated Files:
ExaOptions.tsx- UsesResearchConfigfromresearchApi.tsTavilyOptions.tsx- UsesResearchConfigfromresearchApi.tsResearchInput.tsx- UsesResearchProvider,ResearchModefromresearchApi.tsAdvancedProviderOptionsSection.tsx- UsesResearchProviderfromresearchApi.tsuseResearchWizard.ts- UsesResearchMode,ResearchConfig,ResearchResponsefromresearchApi.tsresearch.types.ts- UsesResearchResponse,ResearchMode,ResearchConfigfromresearchApi.tsStepResults.tsx- UsesResearchResponsefromresearchApi.ts(casts toBlogResearchResponsewhen needed)AdvancedOptionsSection.tsx- UsesResearchConfigfromresearchApi.tsuseResearchConfig.ts- UsesResearchProviderfromresearchApi.tsStepOptions.tsx- UsesResearchProviderfromresearchApi.tsresearchModeSuggester.ts- UsesResearchModefromresearchApi.ts
Backward Compatibility
frontend/src/services/blogWriterApi.ts - Maintains backward compatibility:
- Re-exports research types from
researchApi.tsfor existing blog writer code BlogResearchResponseextendsResearchResponse(adds blog-specific fields likesearch_widget,grounding_metadata)- Blog Writer components continue to work without changes
Adapter Pattern
BlogWriterAdapter.tsx - Uses BlogResearchResponse:
- This is correct - it's an adapter that bridges Research and Blog Writer
- Adapters are allowed to use both APIs as they translate between domains
Architecture
┌─────────────────────────────────────────────────────────┐
│ Research Engine │
│ (Standalone, used by multiple tools) │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ researchApi.ts │ │
│ │ - ResearchConfig │ │
│ │ - ResearchResponse │ │
│ │ - ResearchMode, ResearchProvider │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
│
│ extends
▼
┌─────────────────────────────────────────────────────────┐
│ Blog Writer │
│ (Uses Research Engine) │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ blogWriterApi.ts │ │
│ │ - BlogResearchResponse extends ResearchResponse │ │
│ │ - Blog-specific fields (search_widget, etc.) │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
Benefits
- Clear Separation: Research types are separate from Blog Writer types
- Reusability: Research API can be used by Podcast Maker, YouTube Creator, etc.
- Maintainability: Changes to research don't affect blog writer and vice versa
- Type Safety: Proper TypeScript types ensure compile-time safety
- Backward Compatibility: Existing blog writer code continues to work
Migration Status
✅ Completed:
- Created
researchApi.tswith all research types - Updated all Research components to use
researchApi.ts - Updated
researchEngineApi.tsto useResearchResponse - Maintained backward compatibility in
blogWriterApi.ts BlogResearchResponseproperly extendsResearchResponse
⚠️ Future Work:
- Update blog writer components to import from
researchApi.tsdirectly (currently using re-exports) - Consider creating adapter components for other tools (Podcast Maker, YouTube Creator)
File Structure
frontend/src/services/
├── researchApi.ts ← NEW: Dedicated research types
├── researchEngineApi.ts ← Updated: Uses researchApi.ts
└── blogWriterApi.ts ← Updated: Re-exports + BlogResearchResponse extends ResearchResponse
frontend/src/components/Research/
├── steps/
│ ├── components/
│ │ ├── ExaOptions.tsx ← Uses researchApi.ts
│ │ ├── TavilyOptions.tsx ← Uses researchApi.ts
│ │ └── AdvancedOptionsSection.tsx ← Uses researchApi.ts
│ ├── hooks/
│ │ └── useResearchConfig.ts ← Uses researchApi.ts
│ └── utils/
│ └── researchModeSuggester.ts ← Uses researchApi.ts
├── types/
│ └── research.types.ts ← Uses researchApi.ts
└── integrations/
└── BlogWriterAdapter.tsx ← Uses blogWriterApi.ts (adapter, correct)
Status: ✅ Separation of concerns achieved - Research API is now independent from Blog Writer API