import { GoogleGenAI } from "@google/genai"; import { Context, Next } from "hono"; import { Env, Variables } from "../types"; export async function geminiMiddleware( c: Context<{ Bindings: Env; Variables: Variables }>, next: Next, ) { if (!c.env || !c.env.GEMINI_API_KEY) { return c.json({ success: false, error: "Gemini API key is not specified in worker secrets.", }, 500); } const genAI = new GoogleGenAI({ apiKey: c.env.GEMINI_API_KEY, }); c.set("gemini", genAI); await next(); }