turash/bugulma/frontend/services/aiService.ts
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- Remove nested git repository from bugulma/frontend/.git
- Add all frontend files to main repository tracking
- Convert from separate frontend/backend repos to unified monorepo
- Preserve all frontend code and development history as tracked files
- Eliminate nested repository complexity for simpler development workflow

This creates a proper monorepo structure with frontend and backend
coexisting in the same repository for easier development and deployment.
2025-11-25 06:02:57 +01:00

124 lines
3.4 KiB
TypeScript

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<string> => {
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<Partial<OrganizationFormData>> => {
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<Partial<OrganizationFormData>> => {
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<WebIntelligenceResult> => {
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<string[]> => {
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<string> => {
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<string> => {
try {
return await aiApi.generateHistoricalContext({ landmark });
} catch (error) {
console.error('Error generating historical context:', error);
throw new Error('Failed to generate historical context.');
}
};