/** * Base-URL resolution for the Gemini surfaces that are NOT a single * `generateContent` URL: the Interactions API (`/v1beta/interactions`) and the * Files API (`/upload/v1beta/files`, `/v1beta/files/`). They live on two * different path roots, so one base override (`VCLAW_GEMINI_API_BASE`) covers * both and lets a test point a local http server at every route. * * `VCLAW_GEMINI_API_ENDPOINT` is deliberately NOT read here: that variable is a * full `models/:generateContent` URL and keeps driving the static paths. */ export const DEFAULT_GEMINI_API_BASE = 'https://generativelanguage.googleapis.com'; export function resolveGeminiApiBase(env: NodeJS.ProcessEnv = process.env): string { const raw = env.VCLAW_GEMINI_API_BASE?.trim(); const base = raw && raw !== '' ? raw : DEFAULT_GEMINI_API_BASE; return base.replace(/\/+$/, ''); } /** Append `?key=` / `&key=` the same way every other Gemini call in the repo does. */ export function withKey(url: string, key: string): string { return `${url}${url.includes('?') ? '&' : '?'}key=${encodeURIComponent(key)}`; }