690530:0906 ADR-030-230 context aware #12
This commit is contained in:
@@ -99,7 +99,7 @@ export default function OcrSandboxPromptManager() {
|
||||
(v) => v.isActive === true || (v.isActive as unknown) === 1 || (v.isActive as unknown) === '1'
|
||||
) || versions[0];
|
||||
const [templateText, setTemplateText] = useState<string>('');
|
||||
const [hasLoadedActivePrompt, setHasLoadedActivePrompt] = useState<boolean>(false);
|
||||
const [loadedPromptKey, setLoadedPromptKey] = useState<string | null>(null);
|
||||
const [ocrFile, setOcrFile] = useState<File | null>(null);
|
||||
const [manualNote, setManualNote] = useState<string>('');
|
||||
const [activeTab, setActiveTab] = useState<'editor' | 'sandbox'>('editor');
|
||||
@@ -110,16 +110,20 @@ export default function OcrSandboxPromptManager() {
|
||||
toast.success(t('ai.prompt.sandboxSuccess'));
|
||||
});
|
||||
useEffect(() => {
|
||||
if (versionsQuery.isSuccess) {
|
||||
if (activePrompt && !hasLoadedActivePrompt) {
|
||||
if (!versionsQuery.isSuccess) return;
|
||||
if (activePrompt) {
|
||||
const promptKey = `${activePrompt.promptType}:${activePrompt.versionNumber}`;
|
||||
if (loadedPromptKey !== promptKey) {
|
||||
setTemplateText(activePrompt.template);
|
||||
setHasLoadedActivePrompt(true);
|
||||
} else if (versions.length === 0 && !hasLoadedActivePrompt) {
|
||||
setTemplateText(DEFAULT_OCR_TEMPLATE);
|
||||
setHasLoadedActivePrompt(true);
|
||||
setLoadedPromptKey(promptKey);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}, [activePrompt, versions.length, versionsQuery.isSuccess, hasLoadedActivePrompt]);
|
||||
if (versions.length === 0 && loadedPromptKey === null) {
|
||||
setTemplateText(DEFAULT_OCR_TEMPLATE);
|
||||
setLoadedPromptKey('default');
|
||||
}
|
||||
}, [activePrompt, versions.length, versionsQuery.isSuccess, loadedPromptKey]);
|
||||
const handleSaveVersion = async () => {
|
||||
if (!templateText.includes('{{ocr_text}}')) {
|
||||
toast.error(t('ai.prompt.placeholderError'));
|
||||
|
||||
@@ -7,10 +7,13 @@ import api from '../api/client';
|
||||
import { AiPrompt } from '../../types/ai-prompts';
|
||||
|
||||
const extractData = <T>(value: unknown): T => {
|
||||
if (value && typeof value === 'object' && 'data' in value) {
|
||||
return (value as { data: T }).data;
|
||||
let current: unknown = value;
|
||||
let depth = 0;
|
||||
while (current && typeof current === 'object' && 'data' in current && depth < 5) {
|
||||
current = (current as { data: unknown }).data;
|
||||
depth += 1;
|
||||
}
|
||||
return value as T;
|
||||
return current as T;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -18,9 +21,6 @@ const extractData = <T>(value: unknown): T => {
|
||||
*/
|
||||
const unwrapResponse = <T>(value: unknown): T => {
|
||||
const extracted = extractData<T>(value);
|
||||
if (extracted && typeof extracted === 'object' && 'data' in extracted) {
|
||||
return (extracted as { data: T }).data;
|
||||
}
|
||||
return extracted;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user