turash/bugulma/frontend/hooks/useGemini.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

96 lines
3.3 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import {
analyzeSymbiosis,
extractDataFromFile,
extractDataFromText,
generateHistoricalContext,
generateOrganizationDescription,
getSearchSuggestions,
getWebIntelligence,
sendMessage,
} from '@/services/aiService.ts';
import { canParticipateInResourceMatching } from '@/schemas/organizationSubtype.ts';
import { HistoricalLandmark, Organization } from '@/types.ts';
type TFunction = (key: string, replacements?: { [key: string]: string | number }) => string;
export const useSendMessage = (message: string, systemInstruction: string) => {
return useQuery({
queryKey: ['llm', 'sendMessage', message, systemInstruction],
queryFn: () => sendMessage(message, systemInstruction),
});
};
// Legacy alias for backward compatibility
export const useSendMessageToGemini = useSendMessage;
export const useExtractDataFromText = (text: string, t: TFunction) => {
return useQuery({
queryKey: ['llm', 'extractDataFromText', text],
queryFn: () => extractDataFromText(text, t),
enabled: false, // Only execute on manual refetch
});
};
export const useExtractDataFromFile = (file: File, t: TFunction) => {
return useQuery({
queryKey: ['llm', 'extractDataFromFile', file.name],
queryFn: () => extractDataFromFile(file, t),
enabled: false, // Only execute on manual refetch
});
};
export const useAnalyzeSymbiosis = (
selectedOrg: Organization | null,
allOrgs: Organization[],
t: TFunction
) => {
// Filter to only commercial organizations for matching
const commercialOrgs = allOrgs.filter((org) => canParticipateInResourceMatching(org.Subtype));
return useQuery({
queryKey: ['llm', 'analyzeSymbiosis', selectedOrg?.ID || 'none'],
queryFn: () => analyzeSymbiosis(selectedOrg!, commercialOrgs, t),
enabled: !!selectedOrg && canParticipateInResourceMatching(selectedOrg.Subtype),
});
};
export const useGetWebIntelligence = (organizationName: string | undefined, t: TFunction) => {
return useQuery({
queryKey: ['llm', 'getWebIntelligence', organizationName || 'none'],
queryFn: () => getWebIntelligence(organizationName!, t),
enabled: false, // Only execute on manual refetch - web intelligence should be fetched on-demand
});
};
export const useGetSearchSuggestions = (query: string, t: TFunction) => {
return useQuery({
queryKey: ['llm', 'getSearchSuggestions', query],
queryFn: () => getSearchSuggestions(query, t),
enabled: !!query && query.trim().length >= 2, // Only fetch if query has at least 2 characters
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
placeholderData: [], // Return empty array while loading
});
};
export const useGenerateOrganizationDescription = (
name: string,
sectorKey: string,
keywords: string,
t: TFunction
) => {
return useQuery({
queryKey: ['llm', 'generateOrganizationDescription', name, sectorKey, keywords],
queryFn: () => generateOrganizationDescription(name, sectorKey, keywords, t),
enabled: false, // Only execute on manual refetch
});
};
export const useGenerateHistoricalContext = (landmark: HistoricalLandmark, t: TFunction) => {
return useQuery({
queryKey: ['llm', 'generateHistoricalContext', landmark.id],
queryFn: () => generateHistoricalContext(landmark, t),
enabled: false, // Only execute on manual refetch
});
};