File size: 3,899 Bytes
5d68d7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// The expected structure of a row from the input CSV.
export interface CsvInputRow {
  URL: string;
  Page: string;
  Keywords: string;
  Recommended_Title: string;
  Recommended_H1: string;
  Internal_Links: string;
  Copy: string;
}

// The structure of the 'inputs' object for the Dify API call.
export type ApiInput = CsvInputRow;


// The structure of the `outputs` object from the Dify API response.
export interface ApiResponseOutput {
  title: string;
  h1: string;
  copy: string;
  meta: string;
  qa_gaurd: string;
}

// Represents an item in the processing queue.
export interface QueueItem {
  id: number;
  data: CsvInputRow;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  error?: string;
}

// Represents the parsed QA results for a single section (e.g., Title, H1).
export interface QaSectionResult {
    grade: string;
    pass: boolean;
    errors: string[];
    corrected: string;
    // Enhanced to capture ALL QA Guard content
    detailedAssessment?: string; // Full detailed assessment text
    keyStrengths?: string[]; // List of key strengths identified
    recommendations?: string[]; // List of recommendations
    explanations?: string; // Detailed explanations
    rawContent?: string; // Raw section content for complete preservation
}

// Represents the full, structured QA report.
export interface DetailedQaReport {
    title: QaSectionResult;
    meta: QaSectionResult;
    h1: QaSectionResult;
    copy: QaSectionResult;
    overall: {
        grade: string;
        pass: boolean;
        primaryIssue: string;
        // Enhanced to capture ALL overall assessment content
        detailedAssessment?: string; // Full detailed overall assessment
        keyStrengths?: string[]; // Overall key strengths
        recommendations?: string[]; // Overall recommendations
        explanations?: string; // Detailed overall explanations
        rawContent?: string; // Raw overall section content
    };
    // Capture any additional sections that QA Guard might generate
    additionalSections?: {
        [sectionName: string]: {
            content: string;
            type: 'assessment' | 'strengths' | 'recommendations' | 'explanations' | 'other';
        };
    };
    // Preserve the complete raw QA report
    completeRawReport?: string;
}


// Extracted and cleaned data from the API response.
export interface ProcessedResult {
    generatedTitle: string;
    generatedH1: string;
    generatedCopy: string;
    generatedMeta: string;
    qaReport: string; // The raw, original QA report string
    detailedQaReport?: DetailedQaReport; // The parsed, structured QA report
    overallPass: boolean; // For quick access in the main table view
    overallGrade: string; // For quick access in the main table view
}

// A complete row for the final results table and CSV export.
export type ResultRow = CsvInputRow & ProcessedResult & { id: number };

// Represents a completed job in the history.
export interface JobHistoryItem {
  id: string;
  filename: string;
  date: string;
  totalRows: number;
  completedCount: number;
  failedCount: number;
  results?: ResultRow[]; // Store the full results for review and re-download
}


// Expected headers for the input CSV, used for validation.
export const REQUIRED_CSV_HEADERS: (keyof CsvInputRow)[] = [
    'URL',
    'Page',
    'Keywords',
    'Recommended_Title',
    'Recommended_H1',
    'Internal_Links',
    'Copy'
];

// Structured, user-facing error captured during batching
export interface BatchError {
	row?: number; // 1-based row index for per-row errors
	code: string; // machine-friendly code e.g. CSV_PARSE_ERROR, HTTP_ERROR, SERVICE_UNAVAILABLE
	message: string; // user-friendly message
	suggestion?: string; // optional remediation hint
	at?: 'csv' | 'network' | 'api' | 'stream' | 'parse' | 'unknown';
	debug?: string; // optional raw/console error text to help diagnose
}