refactor AI Analysis system
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 39m7s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 39m7s
This commit is contained in:
52
src/types.ts
52
src/types.ts
@@ -653,6 +653,58 @@ export enum AnalysisType {
|
||||
COMPARE_PRICES = 'COMPARE_PRICES',
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a source for a grounded response, normalized for consistent use in the UI.
|
||||
*/
|
||||
export interface Source {
|
||||
uri: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a response that may include sources, such as from a web search or map plan.
|
||||
*/
|
||||
export interface GroundedResponse {
|
||||
text: string;
|
||||
sources: Source[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the shape of the state managed by the useAiAnalysis hook's reducer.
|
||||
* This centralizes all state related to AI analysis into a single, predictable object.
|
||||
*/
|
||||
export interface AiAnalysisState {
|
||||
// The type of analysis currently being performed, if any.
|
||||
loadingAnalysis: AnalysisType | null;
|
||||
// A general error message for any failed analysis.
|
||||
error: string | null;
|
||||
// Stores the text result for each analysis type.
|
||||
results: { [key in AnalysisType]?: string };
|
||||
// Stores the sources for analyses that provide them.
|
||||
sources: { [key in AnalysisType]?: Source[] };
|
||||
// Stores the URL of the last generated image.
|
||||
generatedImageUrl: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the actions that can be dispatched to the AiAnalysisReducer.
|
||||
* This uses a discriminated union for strict type checking.
|
||||
*/
|
||||
export type AiAnalysisAction =
|
||||
// Dispatched when any analysis starts.
|
||||
| { type: 'FETCH_START'; payload: { analysisType: AnalysisType } }
|
||||
// Dispatched when an analysis that returns a simple string succeeds.
|
||||
| { type: 'FETCH_SUCCESS_TEXT'; payload: { analysisType: AnalysisType; data: string } }
|
||||
// Dispatched when an analysis that returns text and sources succeeds.
|
||||
| { type: 'FETCH_SUCCESS_GROUNDED'; payload: { analysisType: AnalysisType; data: GroundedResponse } }
|
||||
// Dispatched when the image generation succeeds.
|
||||
| { type: 'FETCH_SUCCESS_IMAGE'; payload: { data: string } }
|
||||
// Dispatched when any analysis fails.
|
||||
| { type: 'FETCH_ERROR'; payload: { error: string } }
|
||||
// Dispatched to clear errors or reset state if needed.
|
||||
| { type: 'CLEAR_ERROR' }
|
||||
// Dispatched to reset the state to its initial values.
|
||||
| { type: 'RESET_STATE' };
|
||||
export type StageStatus = 'pending' | 'in-progress' | 'completed' | 'error';
|
||||
|
||||
export interface ProcessingStage {
|
||||
|
||||
Reference in New Issue
Block a user