Compare commits
1 Commits
add-permis
...
7eb4077224
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eb4077224 |
@@ -1,108 +1,61 @@
|
||||
import React, { useState } from 'react';
|
||||
import { AiValidationDialogs } from '../../../components/AiValidationDialogs';
|
||||
import { Product } from '../../../types/product';
|
||||
import { config } from '../../../config';
|
||||
|
||||
interface CurrentPrompt {
|
||||
isOpen: boolean;
|
||||
prompt: string;
|
||||
isLoading: boolean;
|
||||
debugData?: {
|
||||
taxonomyStats: {
|
||||
categories: number;
|
||||
themes: number;
|
||||
colors: number;
|
||||
taxCodes: number;
|
||||
sizeCategories: number;
|
||||
suppliers: number;
|
||||
companies: number;
|
||||
artists: number;
|
||||
} | null;
|
||||
basePrompt: string;
|
||||
sampleFullPrompt: string;
|
||||
promptLength: number;
|
||||
estimatedProcessingTime?: {
|
||||
seconds: number | null;
|
||||
sampleCount: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
import { AiValidationDialogs } from './components/AiValidationDialogs';
|
||||
import { Product } from '../../../../types/products';
|
||||
import {
|
||||
AiValidationProgress,
|
||||
AiValidationDetails,
|
||||
CurrentPrompt as AiValidationCurrentPrompt
|
||||
} from './hooks/useAiValidation';
|
||||
|
||||
const ValidationStepNew: React.FC = () => {
|
||||
const [aiValidationProgress, setAiValidationProgress] = useState(0);
|
||||
const [aiValidationDetails, setAiValidationDetails] = useState('');
|
||||
const [currentPrompt, setCurrentPrompt] = useState<CurrentPrompt>({
|
||||
const [aiValidationProgress, setAiValidationProgress] = useState<AiValidationProgress>({
|
||||
isOpen: false,
|
||||
status: 'idle',
|
||||
step: 0
|
||||
});
|
||||
|
||||
const [aiValidationDetails, setAiValidationDetails] = useState<AiValidationDetails>({
|
||||
changes: [],
|
||||
warnings: [],
|
||||
changeDetails: [],
|
||||
isOpen: false
|
||||
});
|
||||
|
||||
const [currentPrompt, setCurrentPrompt] = useState<AiValidationCurrentPrompt>({
|
||||
isOpen: false,
|
||||
prompt: '',
|
||||
isLoading: true,
|
||||
});
|
||||
const [isChangeReverted, setIsChangeReverted] = useState(false);
|
||||
const [fieldData, setFieldData] = useState<Product[]>([]);
|
||||
|
||||
const showCurrentPrompt = async (products: Product[]) => {
|
||||
setCurrentPrompt((prev) => ({ ...prev, isOpen: true, isLoading: true }));
|
||||
// Track reversion state (for internal use)
|
||||
const [reversionState, setReversionState] = useState<Record<string, boolean>>({});
|
||||
|
||||
try {
|
||||
// Get the prompt
|
||||
const promptResponse = await fetch(`${config.apiUrl}/ai-validation/prompt`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ products })
|
||||
});
|
||||
const [fieldData] = useState<Product[]>([]);
|
||||
|
||||
if (!promptResponse.ok) {
|
||||
throw new Error('Failed to fetch AI prompt');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
const promptData = await promptResponse.json();
|
||||
|
||||
// Get the debug data in the same request or as a separate request
|
||||
const debugResponse = await fetch(`${config.apiUrl}/ai-validation/debug-info`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ prompt: promptData.prompt })
|
||||
});
|
||||
|
||||
let debugData;
|
||||
if (debugResponse.ok) {
|
||||
debugData = await debugResponse.json();
|
||||
} else {
|
||||
// If debug-info fails, use a fallback to get taxonomy stats
|
||||
const fallbackResponse = await fetch(`${config.apiUrl}/ai-validation/debug`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ products: [products[0]] }) // Use first product for stats
|
||||
});
|
||||
|
||||
if (fallbackResponse.ok) {
|
||||
debugData = await fallbackResponse.json();
|
||||
// Set promptLength correctly from the actual prompt
|
||||
debugData.promptLength = promptData.prompt.length;
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentPrompt((prev) => ({
|
||||
...prev,
|
||||
prompt: promptData.prompt,
|
||||
isLoading: false,
|
||||
debugData: debugData
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Error fetching prompt:', error);
|
||||
setCurrentPrompt((prev) => ({
|
||||
...prev,
|
||||
prompt: 'Error loading prompt',
|
||||
isLoading: false
|
||||
}));
|
||||
}
|
||||
const revertAiChange = (productIndex: number, fieldKey: string) => {
|
||||
const key = `${productIndex}-${fieldKey}`;
|
||||
setReversionState(prev => ({
|
||||
...prev,
|
||||
[key]: true
|
||||
}));
|
||||
};
|
||||
|
||||
const revertAiChange = () => {
|
||||
setIsChangeReverted(true);
|
||||
const isChangeReverted = (productIndex: number, fieldKey: string): boolean => {
|
||||
const key = `${productIndex}-${fieldKey}`;
|
||||
return !!reversionState[key];
|
||||
};
|
||||
|
||||
const getFieldDisplayValueWithHighlight = (value: string, highlight: string) => {
|
||||
// Implementation of getFieldDisplayValueWithHighlight
|
||||
const getFieldDisplayValueWithHighlight = (
|
||||
_fieldKey: string,
|
||||
originalValue: any,
|
||||
correctedValue: any
|
||||
) => {
|
||||
return {
|
||||
originalHtml: String(originalValue),
|
||||
correctedHtml: String(correctedValue)
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -166,6 +166,12 @@ export default defineConfig(function (_a) {
|
||||
});
|
||||
},
|
||||
},
|
||||
"/uploads": {
|
||||
target: "https://inventory.kent.pw",
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
rewrite: function (path) { return path; },
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
|
||||
Reference in New Issue
Block a user