690530:0906 ADR-030-230 context aware #12
CI / CD Pipeline / build (push) Successful in 4m54s
CI / CD Pipeline / deploy (push) Successful in 7m49s

This commit is contained in:
2026-05-30 09:06:23 +07:00
parent 63ded10341
commit 1ba563aa70
3 changed files with 460 additions and 14 deletions
@@ -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'));
+6 -6
View File
@@ -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;
};