🐛 Fix: Use direct fetch only for Gemini (remove chrome.runtime.sendMessage which was failing)
This commit is contained in:
@@ -374,35 +374,14 @@
|
|||||||
isGeminiProcessing = true;
|
isGeminiProcessing = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try via background service worker first
|
|
||||||
let processedText = null;
|
let processedText = null;
|
||||||
|
|
||||||
|
// Try direct fetch to server (more reliable than chrome.runtime.sendMessage)
|
||||||
try {
|
try {
|
||||||
const response = await chrome.runtime.sendMessage({
|
const isArabic = /[\u0600-\u06FF]/.test(text);
|
||||||
type: 'GEMINI_PROCESS_VOICE',
|
const langName = isArabic ? 'Arabic' : 'the detected language';
|
||||||
payload: {
|
|
||||||
apiKey: settings.geminiApiKey,
|
|
||||||
model: settings.geminiModel,
|
|
||||||
text: text,
|
|
||||||
language: settings.language
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response && response.success) {
|
const prompt = `You are a text refinement assistant. Your task is to:
|
||||||
processedText = response.data.text;
|
|
||||||
} else {
|
|
||||||
console.warn('[ClaudeVoice] Background response not successful:', response?.error);
|
|
||||||
}
|
|
||||||
} catch (bgErr) {
|
|
||||||
console.warn('[ClaudeVoice] Background message failed, trying direct fetch:', bgErr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: direct fetch to server
|
|
||||||
if (!processedText) {
|
|
||||||
try {
|
|
||||||
const isArabic = /[\u0600-\u06FF]/.test(text);
|
|
||||||
const langName = isArabic ? 'Arabic' : 'the detected language';
|
|
||||||
|
|
||||||
const prompt = `You are a text refinement assistant. Your task is to:
|
|
||||||
|
|
||||||
1. Correct any speech recognition errors in the following text
|
1. Correct any speech recognition errors in the following text
|
||||||
2. Fix punctuation, capitalization, and formatting
|
2. Fix punctuation, capitalization, and formatting
|
||||||
@@ -417,36 +396,35 @@ ${text}
|
|||||||
|
|
||||||
CORRECTED TEXT:`;
|
CORRECTED TEXT:`;
|
||||||
|
|
||||||
const directResponse = await fetch('https://cv.intaleqapp.com/cv/server/generate_cv.php', {
|
const directResponse = await fetch('https://cv.intaleqapp.com/cv/server/generate_cv.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
action: 'generateText',
|
action: 'generateText',
|
||||||
apiKey: settings.geminiApiKey,
|
apiKey: settings.geminiApiKey,
|
||||||
prompt: prompt
|
prompt: prompt
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (directResponse.ok) {
|
if (directResponse.ok) {
|
||||||
const rawText = await directResponse.text();
|
const rawText = await directResponse.text();
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(rawText);
|
data = JSON.parse(rawText);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data = rawText;
|
data = rawText;
|
||||||
}
|
|
||||||
|
|
||||||
if (data && data.candidates && data.candidates[0]) {
|
|
||||||
processedText = data.candidates[0].content?.parts?.[0]?.text;
|
|
||||||
} else if (typeof data === 'string') {
|
|
||||||
processedText = data;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.warn('[ClaudeVoice] Direct fetch failed:', directResponse.status);
|
|
||||||
}
|
}
|
||||||
} catch (fetchErr) {
|
|
||||||
console.warn('[ClaudeVoice] Direct fetch error:', fetchErr);
|
if (data && data.candidates && data.candidates[0]) {
|
||||||
|
processedText = data.candidates[0].content?.parts?.[0]?.text;
|
||||||
|
} else if (typeof data === 'string') {
|
||||||
|
processedText = data;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('[ClaudeVoice] Server fetch failed:', directResponse.status);
|
||||||
}
|
}
|
||||||
|
} catch (fetchErr) {
|
||||||
|
console.warn('[ClaudeVoice] Server fetch error:', fetchErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processedText) {
|
if (processedText) {
|
||||||
|
|||||||
Reference in New Issue
Block a user