@@ -172,6 +172,32 @@ WRAP
|
172 | 172 | if [ ! -x "$NPM_CONFIG_PREFIX/bin/gemini" ]; then |
173 | 173 | npm install -g @google/gemini-cli |
174 | 174 | fi |
| 175 | + if [ -n "${GEMINI_API_KEY:-}" ] || [ -n "${GOOGLE_API_KEY:-}" ]; then |
| 176 | + gemini_auth_type="gemini-api-key" |
| 177 | + if [ -z "${GEMINI_API_KEY:-}" ] && [ -n "${GOOGLE_API_KEY:-}" ]; then |
| 178 | + gemini_auth_type="vertex-ai" |
| 179 | + export GOOGLE_GENAI_USE_VERTEXAI="${GOOGLE_GENAI_USE_VERTEXAI:-true}" |
| 180 | + fi |
| 181 | + GEMINI_CLI_AUTH_TYPE="$gemini_auth_type" node <<'NODE' |
| 182 | +const fs = require("node:fs"); |
| 183 | +const os = require("node:os"); |
| 184 | +const path = require("node:path"); |
| 185 | + |
| 186 | +const settingsPath = path.join(os.homedir(), ".gemini", "settings.json"); |
| 187 | +let settings = {}; |
| 188 | +try { |
| 189 | + settings = JSON.parse(fs.readFileSync(settingsPath, "utf8")); |
| 190 | +} catch {} |
| 191 | +settings.security = settings.security && typeof settings.security === "object" ? settings.security : {}; |
| 192 | +settings.security.auth = |
| 193 | + settings.security.auth && typeof settings.security.auth === "object" ? settings.security.auth : {}; |
| 194 | +settings.security.auth.selectedType = process.env.GEMINI_CLI_AUTH_TYPE; |
| 195 | +settings.security.auth.enforcedType = process.env.GEMINI_CLI_AUTH_TYPE; |
| 196 | +fs.mkdirSync(path.dirname(settingsPath), { recursive: true }); |
| 197 | +fs.writeFileSync(settingsPath, `${JSON.stringify(settings, null, 2)}\n`); |
| 198 | +NODE |
| 199 | + echo "Using Gemini CLI auth type $gemini_auth_type" |
| 200 | + fi |
175 | 201 | ;; |
176 | 202 | opencode) |
177 | 203 | if [ ! -x "$NPM_CONFIG_PREFIX/bin/opencode" ]; then |
|