Behebt den TypeError beim Aufruf von GenerationConfig in der älteren Version der google-generativeai Bibliothek, indem das nicht unterstützte Argument entfernt wird.
113 lines
4.1 KiB
TypeScript
113 lines
4.1 KiB
TypeScript
import { LeadStatus, AnalysisResult, Competitor, Language, Tier, EmailDraft, SearchStrategy, SearchSignal } from "../types";
|
|
|
|
// const apiKey = process.env.API_KEY; // Nicht mehr direkt im Frontend verwendet
|
|
// const ai = new GoogleGenAI({ apiKey: apiKey || '' }); // Nicht mehr direkt im Frontend verwendet
|
|
|
|
// URL unserer lokalen Node.js API-Brücke
|
|
const API_BASE_URL = `http://${window.location.hostname}:3001/api`;
|
|
|
|
// Helper to extract JSON (kann ggf. entfernt werden, wenn das Backend immer sauberes JSON liefert)
|
|
const extractJson = (text: string): any => {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch (e) {
|
|
const jsonMatch = text.match(/```json\s*([\s\S]*?)\s*```/);
|
|
if (jsonMatch && jsonMatch[1]) {
|
|
try { return JSON.parse(jsonMatch[1]); } catch (e2) {}
|
|
}
|
|
const arrayMatch = text.match(/\[\s*[\s\S]*\s*\]/);
|
|
if (arrayMatch) {
|
|
try { return JSON.parse(arrayMatch[0]); } catch (e3) {}
|
|
}
|
|
const objectMatch = text.match(/\{\s*[\s\S]*\s*\}/);
|
|
if (objectMatch) {
|
|
try { return JSON.parse(objectMatch[0]); } catch (e4) {}
|
|
}
|
|
throw new Error("Could not parse JSON response");
|
|
}
|
|
};
|
|
|
|
/**
|
|
* NEU: Ruft unser Python-Backend über die Node.js API-Brücke auf.
|
|
*/
|
|
export const generateSearchStrategy = async (
|
|
referenceUrl: string,
|
|
contextContent: string,
|
|
language: Language
|
|
): Promise<SearchStrategy> => {
|
|
// API-Key wird jetzt vom Backend verwaltet
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/generate-search-strategy`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ referenceUrl, contextContent, language }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
throw new Error(`Backend-Fehler: ${errorData.error || response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
return {
|
|
productContext: data.summaryOfOffer || "Market Analysis",
|
|
idealCustomerProfile: data.idealCustomerProfile || "Companies similar to reference",
|
|
signals: data.signals || []
|
|
};
|
|
} catch (error) {
|
|
console.error("Strategy generation failed via API Bridge", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const identifyCompetitors = async (referenceUrl: string, targetMarket: string, language: Language): Promise<Partial<Competitor>[]> => {
|
|
// Dieser Teil muss noch im Python-Backend implementiert werden
|
|
console.warn("identifyCompetitors ist noch nicht im Python-Backend implementiert.");
|
|
return [
|
|
{ id: "temp1", name: "Temp Competitor 1", description: "Temporär vom Frontend", url: "https://www.google.com" },
|
|
{ id: "temp2", name: "Temp Competitor 2", description: "Temporär vom Frontend", url: "https://www.bing.com" },
|
|
];
|
|
};
|
|
|
|
/**
|
|
* UPDATED: Dynamic Analysis based on Strategy (muss noch im Python-Backend implementiert werden)
|
|
*/
|
|
export const analyzeCompanyWithStrategy = async (
|
|
companyName: string,
|
|
strategy: SearchStrategy,
|
|
language: Language
|
|
): Promise<AnalysisResult> => {
|
|
// Dieser Teil muss noch im Python-Backend implementiert werden
|
|
console.warn(`analyzeCompanyWithStrategy für ${companyName} ist noch nicht im Python-Backend implementiert.`);
|
|
return {
|
|
companyName,
|
|
status: LeadStatus.UNKNOWN,
|
|
revenue: "?",
|
|
employees: "?",
|
|
tier: Tier.TIER_3,
|
|
dataSource: "Frontend Placeholder",
|
|
dynamicAnalysis: {},
|
|
recommendation: "Bitte im Backend implementieren",
|
|
processingChecks: { wiki: false, revenue: false, signalsChecked: false }
|
|
};
|
|
};
|
|
|
|
export const generateOutreachCampaign = async (
|
|
companyData: AnalysisResult,
|
|
knowledgeBase: string,
|
|
language: Language,
|
|
referenceUrl: string
|
|
): Promise<EmailDraft[]> => {
|
|
// Dieser Teil muss noch im Python-Backend implementiert werden
|
|
console.warn("generateOutreachCampaign ist noch nicht im Python-Backend implementiert.");
|
|
return [];
|
|
};
|
|
|
|
export const translateEmailDrafts = async (drafts: EmailDraft[], targetLanguage: Language): Promise<EmailDraft[]> => {
|
|
// Dieser Teil muss noch im Python-Backend oder direkt im Frontend implementiert werden
|
|
console.warn("translateEmailDrafts ist noch nicht im Python-Backend implementiert.");
|
|
return drafts;
|
|
} |