mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-08 21:09:23 +08:00
fix(antigravity): add CLIProxyAPI v6.6.89 compatibility to fix 429 errors
Port Antigravity payload enhancements from CLIProxyAPI v6.6.89: - Add ANTIGRAVITY_SYSTEM_INSTRUCTION with agent identity/guidelines - Inject systemInstruction with role 'user' for Antigravity requests - Add requestType: 'agent' to wrapped request body - Update userAgent to 'antigravity' for Antigravity requests This fixes RESOURCE_EXHAUSTED (429) errors when using Antigravity. Adapted from: https://github.com/NoeFabris/opencode-antigravity-auth/pull/137 Reference: https://github.com/router-for-me/CLIProxyAPI/commit/67985d8
This commit is contained in:
committed by
Peter Steinberger
parent
9eb71b1f88
commit
80ca04af01
@@ -1,8 +1,117 @@
|
||||
diff --git a/dist/providers/google-gemini-cli.js b/dist/providers/google-gemini-cli.js
|
||||
index b1d6a340e1817b6f5404c2a23efa49139249f754..9dd692688fd73d378802af9600e459abbce6a17e 100644
|
||||
index b1d6a340e1817b6f5404c2a23efa49139249f754..6606b09bd4eeee475899a840e6f6fa62b77b6a05 100644
|
||||
--- a/dist/providers/google-gemini-cli.js
|
||||
+++ b/dist/providers/google-gemini-cli.js
|
||||
@@ -168,7 +168,12 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
@@ -7,6 +7,94 @@ import { calculateCost } from "../models.js";
|
||||
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
||||
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
||||
import { convertMessages, convertTools, isThinkingPart, mapStopReasonString, mapToolChoice, retainThoughtSignature, } from "./google-shared.js";
|
||||
+// ============================================================================
|
||||
+// ANTIGRAVITY SYSTEM INSTRUCTION (Ported from CLIProxyAPI v6.6.89)
|
||||
+// ============================================================================
|
||||
+/**
|
||||
+ * System instruction for Antigravity requests.
|
||||
+ * This is injected into requests to match CLIProxyAPI v6.6.89 behavior.
|
||||
+ * The instruction provides identity and guidelines for the Antigravity agent.
|
||||
+ */
|
||||
+const ANTIGRAVITY_SYSTEM_INSTRUCTION = `<identity>
|
||||
+You are Antigravity, a powerful agentic AI coding assistant designed by the Google DeepMind team working on Advanced Agentic Coding.
|
||||
+You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.
|
||||
+The USER will send you requests, which you must always prioritize addressing. Along with each USER request, we will attach additional metadata about their current state, such as what files they have open and where their cursor is.
|
||||
+This information may or may not be relevant to the coding task, it is up for you to decide.
|
||||
+</identity>
|
||||
+
|
||||
+<tool_calling>
|
||||
+Call tools as you normally would. The following list provides additional guidance to help you avoid errors:
|
||||
+ - **Absolute paths only**. When using tools that accept file path arguments, ALWAYS use the absolute file path.
|
||||
+</tool_calling>
|
||||
+
|
||||
+<web_application_development>
|
||||
+## Technology Stack
|
||||
+Your web applications should be built using the following technologies:
|
||||
+1. **Core**: Use HTML for structure and JavaScript for logic.
|
||||
+2. **Styling (CSS)**: Use Vanilla CSS for maximum flexibility and control. Avoid using TailwindCSS unless the USER explicitly requests it; in this case, first confirm which TailwindCSS version to use.
|
||||
+3. **Web App**: If the USER specifies that they want a more complex web app, use a framework like Next.js or Vite. Only do this if the USER explicitly requests a web app.
|
||||
+4. **New Project Creation**: If you need to use a framework for a new app, use \`npx\` with the appropriate script, but there are some rules to follow:
|
||||
+ - Use \`npx -y\` to automatically install the script and its dependencies
|
||||
+ - You MUST run the command with \`--help\` flag to see all available options first
|
||||
+ - Initialize the app in the current directory with \`./\` (example: \`npx -y create-vite-app@latest ./\`)
|
||||
+ - You should run in non-interactive mode so that the user doesn't need to input anything
|
||||
+5. **Running Locally**: When running locally, use \`npm run dev\` or equivalent dev server. Only build the production bundle if the USER explicitly requests it or you are validating the code for correctness.
|
||||
+
|
||||
+# Design Aesthetics
|
||||
+1. **Use Rich Aesthetics**: The USER should be wowed at first glance by the design. Use best practices in modern web design (e.g. vibrant colors, dark modes, glassmorphism, and dynamic animations) to create a stunning first impression. Failure to do this is UNACCEPTABLE.
|
||||
+2. **Prioritize Visual Excellence**: Implement designs that will WOW the user and feel extremely premium:
|
||||
+ - Avoid generic colors (plain red, blue, green). Use curated, harmonious color palettes (e.g., HSL tailored colors, sleek dark modes).
|
||||
+ - Using modern typography (e.g., from Google Fonts like Inter, Roboto, or Outfit) instead of browser defaults.
|
||||
+ - Use smooth gradients
|
||||
+ - Add subtle micro-animations for enhanced user experience
|
||||
+3. **Use a Dynamic Design**: An interface that feels responsive and alive encourages interaction. Achieve this with hover effects and interactive elements. Micro-animations, in particular, are highly effective for improving user engagement.
|
||||
+4. **Premium Designs**: Make a design that feels premium and state of the art. Avoid creating simple minimum viable products.
|
||||
+5. **Don't use placeholders**: If you need an image, use your generate_image tool to create a working demonstration.
|
||||
+
|
||||
+## Implementation Workflow
|
||||
+Follow this systematic approach when building web applications:
|
||||
+1. **Plan and Understand**:
|
||||
+ - Fully understand the user's requirements
|
||||
+ - Draw inspiration from modern, beautiful, and dynamic web designs
|
||||
+ - Outline the features needed for the initial version
|
||||
+2. **Build the Foundation**:
|
||||
+ - Start by creating/modifying \`index.css\`
|
||||
+ - Implement the core design system with all tokens and utilities
|
||||
+3. **Create Components**:
|
||||
+ - Build necessary components using your design system
|
||||
+ - Ensure all components use predefined styles, not ad-hoc utilities
|
||||
+ - Keep components focused and reusable
|
||||
+4. **Assemble Pages**:
|
||||
+ - Update the main application to incorporate your design and components
|
||||
+ - Ensure proper routing and navigation
|
||||
+ - Implement responsive layouts
|
||||
+5. **Polish and Optimize**:
|
||||
+ - Review the overall user experience
|
||||
+ - Ensure smooth interactions and transitions
|
||||
+ - Optimize performance where needed
|
||||
+
|
||||
+## SEO Best Practices
|
||||
+Automatically implement SEO best practices on every page:
|
||||
+- **Title Tags**: Include proper, descriptive title tags for each page
|
||||
+- **Meta Descriptions**: Add compelling meta descriptions that accurately summarize page content
|
||||
+- **Heading Structure**: Use a single \`<h1>\` per page with proper heading hierarchy
|
||||
+- **Semantic HTML**: Use appropriate HTML5 semantic elements
|
||||
+- **Unique IDs**: Ensure all interactive elements have unique, descriptive IDs for browser testing
|
||||
+- **Performance**: Ensure fast page load times through optimization
|
||||
+CRITICAL REMINDER: AESTHETICS ARE VERY IMPORTANT. If your web app looks simple and basic then you have FAILED!
|
||||
+</web_application_development>
|
||||
+<ephemeral_message>
|
||||
+There will be an <EPHEMERAL_MESSAGE> appearing in the conversation at times. This is not coming from the user, but instead injected by the system as important information to pay attention to.
|
||||
+Do not respond to nor acknowledge those messages, but do follow them strictly.
|
||||
+</ephemeral_message>
|
||||
+
|
||||
+
|
||||
+<communication_style>
|
||||
+- **Formatting**. Format your responses in github-style markdown to make your responses easier for the USER to parse. For example, use headers to organize your responses and bolded or italicized text to highlight important keywords. Use backticks to format file, directory, function, and class names. If providing a URL to the user, format this in markdown as well, for example \`[label](example.com)\`.
|
||||
+- **Proactiveness**. As an agent, you are allowed to be proactive, but only in the course of completing the user's task. For example, if the user asks you to add a new component, you can edit the code, verify build and test statuses, and take any other obvious follow-up actions, such as performing additional research. However, avoid surprising the user. For example, if the user asks HOW to approach something, you should answer their question and instead of jumping into editing a file.
|
||||
+- **Helpfulness**. Respond like a helpful software engineer who is explaining your work to a friendly collaborator on the project. Acknowledge mistakes or any backtracking you do as a result of new information.
|
||||
+- **Ask for clarification**. If you are unsure about the USER's intent, always ask for clarification rather than making assumptions.
|
||||
+</communication_style>`;
|
||||
const DEFAULT_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
||||
// Headers for Gemini CLI (prod endpoint)
|
||||
const GEMINI_CLI_HEADERS = {
|
||||
@@ -139,11 +227,12 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
if (!accessToken || !projectId) {
|
||||
throw new Error("Missing token or projectId in Google Cloud credentials. Use /login to re-authenticate.");
|
||||
}
|
||||
- const requestBody = buildRequest(model, context, projectId, options);
|
||||
const endpoint = model.baseUrl || DEFAULT_ENDPOINT;
|
||||
const url = `${endpoint}/v1internal:streamGenerateContent?alt=sse`;
|
||||
// Use Antigravity headers for sandbox endpoint, otherwise Gemini CLI headers
|
||||
const isAntigravity = endpoint.includes("sandbox.googleapis.com");
|
||||
+ // PATCH: Pass isAntigravity to buildRequest for system instruction injection (CLIProxyAPI v6.6.89 compat)
|
||||
+ const requestBody = buildRequest(model, context, projectId, options, isAntigravity);
|
||||
const headers = isAntigravity ? ANTIGRAVITY_HEADERS : GEMINI_CLI_HEADERS;
|
||||
// Fetch with retry logic for rate limits and transient errors
|
||||
let response;
|
||||
@@ -168,7 +257,12 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
break; // Success, exit retry loop
|
||||
}
|
||||
const errorText = await response.text();
|
||||
@@ -16,7 +125,7 @@ index b1d6a340e1817b6f5404c2a23efa49139249f754..9dd692688fd73d378802af9600e459ab
|
||||
if (attempt < MAX_RETRIES && isRetryableError(response.status, errorText)) {
|
||||
// Use server-provided delay or exponential backoff
|
||||
const serverDelay = extractRetryDelay(errorText);
|
||||
@@ -183,6 +188,10 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
@@ -183,6 +277,10 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
if (error instanceof Error && error.message === "Request was aborted") {
|
||||
throw error;
|
||||
}
|
||||
@@ -27,6 +136,42 @@ index b1d6a340e1817b6f5404c2a23efa49139249f754..9dd692688fd73d378802af9600e459ab
|
||||
lastError = error instanceof Error ? error : new Error(String(error));
|
||||
// Network errors are retryable
|
||||
if (attempt < MAX_RETRIES) {
|
||||
@@ -402,7 +500,7 @@ export const streamGoogleGeminiCli = (model, context, options) => {
|
||||
})();
|
||||
return stream;
|
||||
};
|
||||
-function buildRequest(model, context, projectId, options = {}) {
|
||||
+function buildRequest(model, context, projectId, options = {}, isAntigravity = false) {
|
||||
const contents = convertMessages(model, context);
|
||||
const generationConfig = {};
|
||||
if (options.temperature !== undefined) {
|
||||
@@ -447,12 +545,23 @@ function buildRequest(model, context, projectId, options = {}) {
|
||||
};
|
||||
}
|
||||
}
|
||||
- return {
|
||||
+ // PATCH: Inject Antigravity system instruction with role "user" (CLIProxyAPI v6.6.89 compatibility)
|
||||
+ if (isAntigravity) {
|
||||
+ const existingText = request.systemInstruction?.parts?.[0]?.text || "";
|
||||
+ request.systemInstruction = {
|
||||
+ role: "user",
|
||||
+ parts: [{ text: ANTIGRAVITY_SYSTEM_INSTRUCTION + (existingText ? "\n\n" + existingText : "") }],
|
||||
+ };
|
||||
+ }
|
||||
+ // PATCH: Build wrapped body with requestType for Antigravity (CLIProxyAPI v6.6.89 compatibility)
|
||||
+ const wrappedBody = {
|
||||
project: projectId,
|
||||
model: model.id,
|
||||
request,
|
||||
- userAgent: "pi-coding-agent",
|
||||
- requestId: `pi-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
||||
+ ...(isAntigravity && { requestType: "agent" }),
|
||||
+ userAgent: isAntigravity ? "antigravity" : "pi-coding-agent",
|
||||
+ requestId: `${isAntigravity ? "agent" : "pi"}-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
||||
};
|
||||
+ return wrappedBody;
|
||||
}
|
||||
//# sourceMappingURL=google-gemini-cli.js.map
|
||||
diff --git a/dist/providers/google-shared.js b/dist/providers/google-shared.js
|
||||
index dbb9c0e263919c9184a5f1c7dfde47d1c3a37ff4..f1866f423f30a4dfbe812d052679abd1f011769f 100644
|
||||
--- a/dist/providers/google-shared.js
|
||||
|
||||
Reference in New Issue
Block a user