Compare commits
1 Commits
add-permis
...
7eb4077224
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eb4077224 |
@@ -1,108 +1,61 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { AiValidationDialogs } from '../../../components/AiValidationDialogs';
|
import { AiValidationDialogs } from './components/AiValidationDialogs';
|
||||||
import { Product } from '../../../types/product';
|
import { Product } from '../../../../types/products';
|
||||||
import { config } from '../../../config';
|
import {
|
||||||
|
AiValidationProgress,
|
||||||
interface CurrentPrompt {
|
AiValidationDetails,
|
||||||
isOpen: boolean;
|
CurrentPrompt as AiValidationCurrentPrompt
|
||||||
prompt: string;
|
} from './hooks/useAiValidation';
|
||||||
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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const ValidationStepNew: React.FC = () => {
|
const ValidationStepNew: React.FC = () => {
|
||||||
const [aiValidationProgress, setAiValidationProgress] = useState(0);
|
const [aiValidationProgress, setAiValidationProgress] = useState<AiValidationProgress>({
|
||||||
const [aiValidationDetails, setAiValidationDetails] = useState('');
|
isOpen: false,
|
||||||
const [currentPrompt, setCurrentPrompt] = useState<CurrentPrompt>({
|
status: 'idle',
|
||||||
|
step: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
const [aiValidationDetails, setAiValidationDetails] = useState<AiValidationDetails>({
|
||||||
|
changes: [],
|
||||||
|
warnings: [],
|
||||||
|
changeDetails: [],
|
||||||
|
isOpen: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const [currentPrompt, setCurrentPrompt] = useState<AiValidationCurrentPrompt>({
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
prompt: '',
|
prompt: '',
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
});
|
});
|
||||||
const [isChangeReverted, setIsChangeReverted] = useState(false);
|
|
||||||
const [fieldData, setFieldData] = useState<Product[]>([]);
|
|
||||||
|
|
||||||
const showCurrentPrompt = async (products: Product[]) => {
|
// Track reversion state (for internal use)
|
||||||
setCurrentPrompt((prev) => ({ ...prev, isOpen: true, isLoading: true }));
|
const [reversionState, setReversionState] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
try {
|
const [fieldData] = useState<Product[]>([]);
|
||||||
// Get the prompt
|
|
||||||
const promptResponse = await fetch(`${config.apiUrl}/ai-validation/prompt`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ products })
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!promptResponse.ok) {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
throw new Error('Failed to fetch AI prompt');
|
|
||||||
}
|
|
||||||
|
|
||||||
const promptData = await promptResponse.json();
|
const revertAiChange = (productIndex: number, fieldKey: string) => {
|
||||||
|
const key = `${productIndex}-${fieldKey}`;
|
||||||
// Get the debug data in the same request or as a separate request
|
setReversionState(prev => ({
|
||||||
const debugResponse = await fetch(`${config.apiUrl}/ai-validation/debug-info`, {
|
...prev,
|
||||||
method: 'POST',
|
[key]: true
|
||||||
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 = () => {
|
const isChangeReverted = (productIndex: number, fieldKey: string): boolean => {
|
||||||
setIsChangeReverted(true);
|
const key = `${productIndex}-${fieldKey}`;
|
||||||
|
return !!reversionState[key];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFieldDisplayValueWithHighlight = (value: string, highlight: string) => {
|
const getFieldDisplayValueWithHighlight = (
|
||||||
// Implementation of getFieldDisplayValueWithHighlight
|
_fieldKey: string,
|
||||||
|
originalValue: any,
|
||||||
|
correctedValue: any
|
||||||
|
) => {
|
||||||
|
return {
|
||||||
|
originalHtml: String(originalValue),
|
||||||
|
correctedHtml: String(correctedValue)
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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: {
|
build: {
|
||||||
|
|||||||
Reference in New Issue
Block a user