Enlace Neural Backend (Seguro)
Las claves API nunca se almacenan en el navegador. Conecta tu endpoint proxy (Cloudflare Worker, Node/Express o Supabase).
Nota: Por seguridad, el token de sesión no se persiste en localStorage al cerrar la pestaña.
Despliega este código en Cloudflare Workers o Node.js/Express guardando tu clave en la variable de entorno GEMINI_API_KEY:
// server-proxy.js — Backend seguro para J.A.R.V.I.S. (Cloudflare Worker / Node.js)
// Guarda GEMINI_API_KEY como variable de entorno secreta en tu servidor, NUNCA en el frontend.
export default {
async fetch(request, env) {
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
if (request.method === "OPTIONS") {
return new Response(null, { headers: corsHeaders });
}
// Endpoint de diagnóstico de salud (/api/jarvis?health=1)
const url = new URL(request.url);
if (request.method === "GET" && url.searchParams.get("health") === "1") {
return new Response(
JSON.stringify({ ok: true, service: "J.A.R.V.I.S. Secure Proxy", timestamp: Date.now() }),
{ headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
if (request.method !== "POST") {
return new Response(JSON.stringify({ error: "Método no permitido" }), {
status: 405,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
// Validación opcional de token de sesión propio
if (env.JARVIS_SESSION_TOKEN) {
const auth = request.headers.get("Authorization") || "";
if (auth !== `Bearer ${env.JARVIS_SESSION_TOKEN}`) {
return new Response(JSON.stringify({ error: "No autorizado" }), {
status: 401,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
}
try {
const { messages, systemPrompt } = await request.json();
const geminiRes = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${env.GEMINI_API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
systemInstruction: { parts: [{ text: systemPrompt || "Eres J.A.R.V.I.S." }] },
contents: messages,
}),
}
);
const data = await geminiRes.json();
const reply = data?.candidates?.[0]?.content?.parts?.[0]?.text || "Sin respuesta del núcleo.";
return new Response(JSON.stringify({ reply }), {
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
},
};
Módulo Vocal (SpeechSynthesis)
Despliegue PWA & Android
SW LISTO PARA EXPORTAR
Esta aplicación incluye Manifiesto Web y Service Worker activos. También puedes descargar el paquete completo de archivos separados (index.html, manifest.json, sw.js, server-proxy.js) para alojarlo en Cloudflare Pages, GitHub Pages o instalarlo en Android como APK/TWA.