import type { HistoricalLandmark, Organization, OrganizationFormData, WebIntelligenceResult, } from '@/types'; import * as aiApi from '@/services/ai-api'; /** * Sends a simple text message to the AI via backend */ export const sendMessage = async (message: string, systemInstruction?: string): Promise => { return aiApi.sendMessage({ message, system_instruction: systemInstruction }); }; /** * Extracts structured organization data from a block of text via backend */ export const extractDataFromText = async (text: string): Promise> => { try { return await aiApi.extractDataFromText({ text }); } catch (error) { console.error('Error extracting data from text:', error); throw new Error('Failed to extract data from text.'); } }; /** * Extracts structured organization data from an image file via backend */ export const extractDataFromFile = async (file: File): Promise> => { if (!file.type.startsWith('image/')) { throw new Error('Unsupported file type. Please upload an image.'); } try { return await aiApi.extractDataFromFile({ file }); } catch (error) { console.error('Error extracting data from file:', error); throw new Error('Failed to extract data from file.'); } }; /** * Analyzes potential symbiotic relationships for an organization via backend */ export const analyzeSymbiosis = async ( selectedOrg: Organization ): Promise<{ matches: Array<{ partner_id: string; partner_name: string; reason: string; score: number; }>; }> => { try { return await aiApi.analyzeSymbiosis({ organization_id: selectedOrg.ID, }); } catch (error) { console.error('Error analyzing symbiosis:', error); throw new Error('Failed to analyze symbiotic connections.'); } }; /** * Fetches a summary of a company's recent web presence via backend */ export const getWebIntelligence = async ( organizationName: string ): Promise => { try { return await aiApi.getWebIntelligence({ organization_name: organizationName }); } catch (error) { console.error('Error fetching web intelligence:', error); throw new Error('Failed to fetch web intelligence.'); } }; /** * Generates relevant search suggestions via backend */ export const getSearchSuggestions = async (query: string): Promise => { try { return await aiApi.getSearchSuggestions({ query }); } catch (error) { console.error('Error getting search suggestions:', error); return []; // Return empty array on failure } }; /** * Generates a professional company description via backend */ export const generateOrganizationDescription = async ( name: string, sectorKey: string, keywords: string ): Promise => { try { return await aiApi.generateOrganizationDescription({ name, sector_key: sectorKey, keywords, }); } catch (error) { console.error('Error generating organization description:', error); throw new Error('Failed to generate description.'); } }; /** * Generates an engaging historical context paragraph for a landmark via backend */ export const generateHistoricalContext = async (landmark: HistoricalLandmark): Promise => { try { return await aiApi.generateHistoricalContext({ landmark }); } catch (error) { console.error('Error generating historical context:', error); throw new Error('Failed to generate historical context.'); } };