690605:1247 ADR-034-134 #11 fix Step 2
CI / CD Pipeline / build (push) Successful in 6m5s
CI / CD Pipeline / deploy (push) Successful in 6m30s

This commit is contained in:
2026-06-05 12:47:38 +07:00
parent 4a808dd9c4
commit 548dba6476
5 changed files with 39 additions and 34 deletions
@@ -147,7 +147,7 @@ export default function OcrSandboxPromptManager() {
fallbackUsed?: boolean;
} | null>(null);
const [selectedPromptVersion, setSelectedPromptVersion] = useState<number | undefined>(undefined);
const { state: sandboxState, jobId: sandboxJobId, reset: resetSandbox } =
const { state: sandboxState, jobId: sandboxJobId, reset: resetSandbox, startPolling } =
useSandboxRun(() => {
// เมื่อ sandbox เสร็จสิ้น: รีเฟรชรายการเวอร์ชัน
versionsQuery.refetch();
@@ -285,24 +285,8 @@ export default function OcrSandboxPromptManager() {
selectedPromptVersion
);
toast.success('AI Extraction started');
// Poll สำหรับผลลัพธ์ AI
const pollInterval = setInterval(async () => {
try {
const result = await adminAiService.getSandboxJobStatus(requestPublicId);
if (result.status === 'completed') {
clearInterval(pollInterval);
// Trigger sandbox state update via useSandboxRun
toast.success(t('ai.prompt.sandboxSuccess'));
versionsQuery.refetch();
} else if (result.status === 'failed') {
clearInterval(pollInterval);
toast.error(result.errorMessage || 'AI Extraction failed');
}
} catch (_err) {
clearInterval(pollInterval);
toast.error('Poll error occurred');
}
}, 1000);
// เริ่ม polling ผ่าน useSandboxRun hook
startPolling(requestPublicId);
} catch (err: unknown) {
const error = err as { response?: { data?: { message?: string } } };
toast.error(error.response?.data?.message || 'AI Extraction failed');