feat: Gemini AI integration — conversations, messages, image gen

- Fixed YAML parse error (unquoted colon in description broke @scalar/json-magic)
- Converted orval.config.ts → orval.config.cjs (fixes orval v8 TypeScript config loading)
- Codegen now works: zod schemas + React Query hooks regenerated with Gemini types
- Added Gemini tag, 4 path groups, 8 schemas to openapi.yaml
- lib/integrations-gemini-ai wired: tsconfig refs, api-server package.json dep
- Created routes/gemini.ts: CRUD conversations/messages + SSE chat stream + image gen
- Mounted /gemini router in routes/index.ts
This commit is contained in:
Replit Agent
2026-03-20 02:41:12 +00:00
parent cdb104e34f
commit e86dab0d65
54 changed files with 3620 additions and 28 deletions

View File

@@ -0,0 +1,47 @@
import { GoogleGenAI, Modality } from "@google/genai";
if (!process.env.AI_INTEGRATIONS_GEMINI_BASE_URL) {
throw new Error(
"AI_INTEGRATIONS_GEMINI_BASE_URL must be set. Did you forget to provision the Gemini AI integration?",
);
}
if (!process.env.AI_INTEGRATIONS_GEMINI_API_KEY) {
throw new Error(
"AI_INTEGRATIONS_GEMINI_API_KEY must be set. Did you forget to provision the Gemini AI integration?",
);
}
export const ai = new GoogleGenAI({
apiKey: process.env.AI_INTEGRATIONS_GEMINI_API_KEY,
httpOptions: {
apiVersion: "",
baseUrl: process.env.AI_INTEGRATIONS_GEMINI_BASE_URL,
},
});
export async function generateImage(
prompt: string
): Promise<{ b64_json: string; mimeType: string }> {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: [{ role: "user", parts: [{ text: prompt }] }],
config: {
responseModalities: [Modality.TEXT, Modality.IMAGE],
},
});
const candidate = response.candidates?.[0];
const imagePart = candidate?.content?.parts?.find(
(part: { inlineData?: { data?: string; mimeType?: string } }) => part.inlineData
);
if (!imagePart?.inlineData?.data) {
throw new Error("No image data in response");
}
return {
b64_json: imagePart.inlineData.data,
mimeType: imagePart.inlineData.mimeType || "image/png",
};
}

View File

@@ -0,0 +1 @@
export { ai, generateImage } from "./client";