32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
/**
|
||
* Gerçek AI şartname analizi istemcisi (backend /api/ai üzerinden).
|
||
*/
|
||
import { getToken } from './auth';
|
||
|
||
export async function getAiConfig() {
|
||
try {
|
||
const res = await fetch('/api/ai/config');
|
||
if (!res.ok) return { configured: false, providers: [] };
|
||
return await res.json();
|
||
} catch {
|
||
return { configured: false, providers: [] };
|
||
}
|
||
}
|
||
|
||
export async function analyzeSpecText({ text, fileName, tender, chain, mode, extraction }) {
|
||
const res = await fetch('/api/ai/analyze', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
|
||
body: JSON.stringify({ text, fileName, tender, chain, mode, extraction }),
|
||
});
|
||
const data = await res.json().catch(() => ({}));
|
||
if (!data.success) {
|
||
const proxyMesaj = {
|
||
413: 'Doküman metni sunucu sınırını aşıyor; daha küçük bir dosya veya yalnızca ilgili sayfaları deneyin.',
|
||
504: 'Analiz zaman aşımına uğradı; tekrar deneyin (derin analiz 1-2 dk sürebilir).',
|
||
}[res.status];
|
||
throw new Error(data.error || proxyMesaj || `Analiz başarısız (HTTP ${res.status})`);
|
||
}
|
||
return data;
|
||
}
|