clawmoney 0.14.4 → 0.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -253,13 +253,70 @@ export function getGeminiRateGuardSnapshot() {
|
|
|
253
253
|
return rateGuard?.currentLoad() ?? null;
|
|
254
254
|
}
|
|
255
255
|
// ── Preflight ──
|
|
256
|
+
//
|
|
257
|
+
// Real Gemini CLI's startup sequence (packages/core/src/code_assist/
|
|
258
|
+
// setup.ts:164) ALWAYS calls loadCodeAssist once at launch, before any
|
|
259
|
+
// user prompt hits generateContentStream. That call:
|
|
260
|
+
// - registers the client instance with Code Assist
|
|
261
|
+
// - warms any server-side caches tied to the project
|
|
262
|
+
// - establishes the "this account has a normal CLI session" pattern
|
|
263
|
+
// that the fraud pipeline uses to distinguish genuine CLI users
|
|
264
|
+
// from bare-API abusers
|
|
265
|
+
// Our daemon used to jump straight to streamGenerateContent, which on
|
|
266
|
+
// a cold account looks like "first request is a raw model call, no
|
|
267
|
+
// setup ceremony" — a distinctive bot fingerprint. Mirror the real CLI
|
|
268
|
+
// by calling loadCodeAssist exactly once per daemon boot. Silently
|
|
269
|
+
// swallow any error so a flaky setup call doesn't tank the daemon.
|
|
270
|
+
async function warmupLoadCodeAssist(projectId, accessToken, userAgent, xGoogApiClient) {
|
|
271
|
+
const url = `${CODE_ASSIST_BASE_URL}/v1internal:loadCodeAssist`;
|
|
272
|
+
const body = JSON.stringify({
|
|
273
|
+
cloudaicompanionProject: projectId,
|
|
274
|
+
metadata: {
|
|
275
|
+
// Matches real CLI constant set from setup.ts:154-158. Note
|
|
276
|
+
// `ideType: IDE_UNSPECIFIED` — that's the CLI default, Antigravity
|
|
277
|
+
// uses a different value and we must NOT leak the two signals.
|
|
278
|
+
ideType: "IDE_UNSPECIFIED",
|
|
279
|
+
platform: "PLATFORM_UNSPECIFIED",
|
|
280
|
+
pluginType: "GEMINI",
|
|
281
|
+
duetProject: projectId,
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
try {
|
|
285
|
+
const resp = await fetch(url, {
|
|
286
|
+
method: "POST",
|
|
287
|
+
headers: {
|
|
288
|
+
"content-type": "application/json",
|
|
289
|
+
"accept": "application/json",
|
|
290
|
+
"authorization": `Bearer ${accessToken}`,
|
|
291
|
+
"user-agent": userAgent,
|
|
292
|
+
"x-goog-api-client": xGoogApiClient,
|
|
293
|
+
},
|
|
294
|
+
body,
|
|
295
|
+
});
|
|
296
|
+
if (!resp.ok) {
|
|
297
|
+
logger.warn(`[gemini-api] warmup loadCodeAssist non-OK (${resp.status}) — continuing`);
|
|
298
|
+
// Drain body to release the connection.
|
|
299
|
+
await resp.text().catch(() => "");
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
await resp.text().catch(() => "");
|
|
303
|
+
logger.info("[gemini-api] warmup loadCodeAssist OK");
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
logger.warn(`[gemini-api] warmup loadCodeAssist error — continuing: ${err.message}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
256
309
|
export async function preflightGeminiApi(config) {
|
|
257
310
|
configureDispatcher();
|
|
258
311
|
configureGeminiRateGuard(config);
|
|
259
|
-
loadFingerprint();
|
|
260
|
-
await getFreshCreds();
|
|
312
|
+
const fingerprint = loadFingerprint();
|
|
313
|
+
const creds = await getFreshCreds();
|
|
261
314
|
logger.info(`[gemini-api] preflight OK (project=${cachedFingerprint?.project_id ?? "?"}, ` +
|
|
262
315
|
`ua=${cachedFingerprint?.user_agent ?? "?"})`);
|
|
316
|
+
// Warmup call — mirror real CLI startup before the first user prompt.
|
|
317
|
+
// Done after token refresh so the request goes out with a fresh access
|
|
318
|
+
// token (expired-token warmups would look like another bot signal).
|
|
319
|
+
await warmupLoadCodeAssist(fingerprint.project_id, creds.access_token, fingerprint.user_agent, fingerprint.x_goog_api_client);
|
|
263
320
|
}
|
|
264
321
|
export async function callGeminiApi(opts) {
|
|
265
322
|
configureDispatcher();
|