feat(gemini-cli): wrap CloudCode payload and surface 429 retryDelay
- Send { project, model, request } envelope expected by Cloud Code Assist
- Parse google.rpc.RetryInfo from 429 responses to expose retry hint
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
eaf770a28e
commit
3e52af35e2
1 changed files with 26 additions and 4 deletions
|
|
@ -25,10 +25,32 @@ export class GeminiCLIExecutor extends BaseExecutor {
|
||||||
transformRequest(model, body, stream, credentials) {
|
transformRequest(model, body, stream, credentials) {
|
||||||
// Store model for use in buildHeaders (called by base.execute after transformRequest)
|
// Store model for use in buildHeaders (called by base.execute after transformRequest)
|
||||||
this._currentModel = model;
|
this._currentModel = model;
|
||||||
if (!body.project && credentials?.projectId) {
|
// Cloud Code Assist wraps the Gemini payload: { project, model, request: <body> }
|
||||||
body.project = credentials.projectId;
|
if (body && body.request && body.model) return body;
|
||||||
}
|
return {
|
||||||
return body;
|
project: credentials?.projectId || body?.project,
|
||||||
|
model,
|
||||||
|
request: body
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse RetryInfo.retryDelay from Google API 429 body to surface upstream retry hint
|
||||||
|
parseError(response, bodyText) {
|
||||||
|
const base = super.parseError(response, bodyText);
|
||||||
|
if (response.status !== 429 || !bodyText) return base;
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(bodyText);
|
||||||
|
const details = parsed?.error?.details;
|
||||||
|
if (Array.isArray(details)) {
|
||||||
|
for (const d of details) {
|
||||||
|
if (d?.["@type"] === "type.googleapis.com/google.rpc.RetryInfo" && d?.retryDelay) {
|
||||||
|
base.retryAfter = d.retryDelay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshCredentials(credentials, log) {
|
async refreshCredentials(credentials, log) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue