import fetch from 'node-fetch'; import { d as private_env } from './shared-server-49TKSBDM.js'; import dns from 'node:dns'; dns.setDefaultResultOrder("ipv4first"); class FullTextSearchService { url = ""; constructor(url) { this.url = url; } async health() { try { const r = await fetch(`${this.url}/health`, { method: "GET", headers: { "Content-Type": "application/json" } }); const data = await r.json(); if (data.status === "ok") { return data.status; } } catch (error) { console.log(JSON.parse(JSON.stringify(error))); } return "unavailable"; } async search(query, use_llm_for_teasers, do_multistep_search, use_accounting_docs, use_reranking, disable_thresholds, use_llm_for_filtering, find_transaction_maps_by_question, find_transaction_maps_by_operation, use_keywords, { abortController }) { const timeoutId = setTimeout(() => { abortController.abort(); }, 6e4 * Number(private_env.SEARCH_API_REQUEST_TIMEOUT)); const startTime = Date.now(); try { const r = await fetch(`${this.url}/search`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "query": query, "top": 30, "use_llm_for_teasers": use_llm_for_teasers, "do_multistep_search": do_multistep_search, "use_accounting_docs": use_accounting_docs, "use_reranking": use_reranking, "disable_thresholds": disable_thresholds, "use_llm_for_filtering": use_llm_for_filtering, "find_transaction_maps_by_question": find_transaction_maps_by_question, "find_transaction_maps_by_operation": find_transaction_maps_by_operation, "use_keywords": use_keywords }), signal: abortController.signal }); if (!r.ok) { console.error(`Failed to load search results: ${await r.text()}`); throw new Error(`Не удалось загрузить результаты поиска. Возможно, поиск ещё не запустился. Попробуйте отправить запрос ещё раз.`); } const response = await r.json(); if (find_transaction_maps_by_question || find_transaction_maps_by_operation) { return { transactionMapResults: response.transaction_maps_results, searchResults: null, consultations: null }; } else { return { transactionMapResults: null, searchResults: response.results, consultations: response.consultations }; } } catch (error) { if (abortController.signal.aborted || error.name === "AbortError") { throw new Error(`Сервис поиска не отвечает. Попробуйте изменить и повторить запрос'`); } console.log(JSON.parse(JSON.stringify(error))); throw error; } finally { const endTime = Date.now(); const difference = Math.abs(endTime - startTime) / 1e3; console.log("Search response time:", difference); clearTimeout(timeoutId); } } } export { FullTextSearchService as F }; //# sourceMappingURL=FullTextSearchService-0xoNRjpt.js.map