forked from tctinh/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconstants.ts
More file actions
260 lines (219 loc) · 10.4 KB
/
constants.ts
File metadata and controls
260 lines (219 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* Constants used for Antigravity OAuth flows and Cloud Code Assist API integration.
*/
export const ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
/**
* Client secret issued for the Antigravity OAuth application.
*/
export const ANTIGRAVITY_CLIENT_SECRET = "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";
/**
* Scopes required for Antigravity integrations.
*/
export const ANTIGRAVITY_SCOPES: readonly string[] = [
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/cclog",
"https://www.googleapis.com/auth/experimentsandconfigs",
];
/**
* OAuth redirect URI used by the local CLI callback server.
*/
export const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
/**
* Root endpoints for the Antigravity API (in fallback order).
* CLIProxy and Vibeproxy use the daily sandbox endpoint first,
* then fallback to autopush and prod if needed.
*/
export const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
export const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
export const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
/**
* Endpoint fallback order (daily → autopush → prod).
* Shared across request handling and project discovery to mirror CLIProxy behavior.
*/
export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
ANTIGRAVITY_ENDPOINT_DAILY,
ANTIGRAVITY_ENDPOINT_AUTOPUSH,
ANTIGRAVITY_ENDPOINT_PROD,
] as const;
/**
* Preferred endpoint order for project discovery (prod first, then fallbacks).
* loadCodeAssist appears to be best supported on prod for managed project resolution.
*/
export const ANTIGRAVITY_LOAD_ENDPOINTS = [
ANTIGRAVITY_ENDPOINT_PROD,
ANTIGRAVITY_ENDPOINT_DAILY,
ANTIGRAVITY_ENDPOINT_AUTOPUSH,
] as const;
/**
* Primary endpoint to use (daily sandbox - same as CLIProxy/Vibeproxy).
*/
export const ANTIGRAVITY_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
/**
* Gemini CLI endpoint (production).
* Used for models without :antigravity suffix.
* Same as opencode-gemini-auth's GEMINI_CODE_ASSIST_ENDPOINT.
*/
export const GEMINI_CLI_ENDPOINT = ANTIGRAVITY_ENDPOINT_PROD;
/**
* Hardcoded project id used when Antigravity does not return one (e.g., business/workspace accounts).
*/
export const ANTIGRAVITY_DEFAULT_PROJECT_ID = "rising-fact-p41fc";
export const ANTIGRAVITY_VERSION_FALLBACK = "1.19.4";
let antigravityVersion = ANTIGRAVITY_VERSION_FALLBACK;
let versionLocked = false;
export function getAntigravityVersion(): string { return antigravityVersion; }
/**
* Set the runtime Antigravity version. Can only be called once (at startup).
* Subsequent calls are silently ignored to prevent accidental mutation.
*/
export function setAntigravityVersion(version: string): void {
if (versionLocked) return;
antigravityVersion = version;
versionLocked = true;
}
/** @deprecated Use getAntigravityVersion() for runtime access. */
export const ANTIGRAVITY_VERSION = ANTIGRAVITY_VERSION_FALLBACK;
export function getAntigravityHeaders(): HeaderSet & { "Client-Metadata": string } {
return {
"User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${getAntigravityVersion()} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
"Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`,
};
}
/** @deprecated Use getAntigravityHeaders() for runtime access. */
export const ANTIGRAVITY_HEADERS = {
"User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${ANTIGRAVITY_VERSION} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
"Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`,
} as const;
export const GEMINI_CLI_HEADERS = {
"User-Agent": "google-api-nodejs-client/9.15.1",
"X-Goog-Api-Client": "gl-node/22.17.0",
"Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI",
} as const;
const ANTIGRAVITY_PLATFORMS = ["windows/amd64", "darwin/arm64", "darwin/amd64"] as const;
const ANTIGRAVITY_API_CLIENTS = [
"google-cloud-sdk vscode_cloudshelleditor/0.1",
"google-cloud-sdk vscode/1.96.0",
"google-cloud-sdk vscode/1.95.0",
] as const;
function randomFrom<T>(arr: readonly T[]): T {
return arr[Math.floor(Math.random() * arr.length)]!;
}
export type HeaderSet = {
"User-Agent": string;
"X-Goog-Api-Client"?: string;
"Client-Metadata"?: string;
};
export function getRandomizedHeaders(style: HeaderStyle, model?: string): HeaderSet {
if (style === "gemini-cli") {
return {
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
"X-Goog-Api-Client": GEMINI_CLI_HEADERS["X-Goog-Api-Client"],
"Client-Metadata": GEMINI_CLI_HEADERS["Client-Metadata"],
};
}
const platform = randomFrom(ANTIGRAVITY_PLATFORMS);
const metadataPlatform = platform.startsWith("windows") ? "WINDOWS" : "MACOS";
return {
"User-Agent": `antigravity/${getAntigravityVersion()} ${platform}`,
"X-Goog-Api-Client": randomFrom(ANTIGRAVITY_API_CLIENTS),
"Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${metadataPlatform}","pluginType":"GEMINI"}`,
};
}
export type HeaderStyle = "antigravity" | "gemini-cli";
/**
* Provider identifier shared between the plugin loader and credential store.
*/
export const ANTIGRAVITY_PROVIDER_ID = "google";
// ============================================================================
// TOOL HALLUCINATION PREVENTION (Ported from LLM-API-Key-Proxy)
// ============================================================================
/**
* System instruction for Claude tool usage hardening.
* Prevents hallucinated parameters by explicitly stating the rules.
*
* This is injected when tools are present to reduce cases where Claude
* uses parameter names from its training data instead of the actual schema.
*/
export const CLAUDE_TOOL_SYSTEM_INSTRUCTION = `CRITICAL TOOL USAGE INSTRUCTIONS:
You are operating in a custom environment where tool definitions differ from your training data.
You MUST follow these rules strictly:
1. DO NOT use your internal training data to guess tool parameters
2. ONLY use the exact parameter structure defined in the tool schema
3. Parameter names in schemas are EXACT - do not substitute with similar names from your training
4. Array parameters have specific item types - check the schema's 'items' field for the exact structure
5. When you see "STRICT PARAMETERS" in a tool description, those type definitions override any assumptions
6. Tool use in agentic workflows is REQUIRED - you must call tools with the exact parameters specified
If you are unsure about a tool's parameters, YOU MUST read the schema definition carefully.`;
/**
* Template for parameter signature injection into tool descriptions.
* {params} will be replaced with the actual parameter list.
*/
export const CLAUDE_DESCRIPTION_PROMPT = "\n\n⚠️ STRICT PARAMETERS: {params}.";
export const EMPTY_SCHEMA_PLACEHOLDER_NAME = "_placeholder";
export const EMPTY_SCHEMA_PLACEHOLDER_DESCRIPTION = "Placeholder. Always pass true.";
/**
* Sentinel value to bypass thought signature validation.
*
* When a thinking block has an invalid or missing signature (e.g., cache miss,
* session mismatch, plugin restart), this sentinel can be injected to skip
* validation instead of failing with "Invalid signature in thinking block".
*
* This is an officially supported Google API feature, used by:
* - gemini-cli: https://github.com/google-gemini/gemini-cli
* - Google .NET SDK: PredictionServiceChatClient.cs
*
* @see https://ai.google.dev/gemini-api/docs/thought-signatures
*/
export const SKIP_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
// ============================================================================
// 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.
*/
// ============================================================================
// GOOGLE SEARCH TOOL CONSTANTS
// ============================================================================
/**
* Model used for Google Search grounding requests.
* Uses gemini-2.5-flash for fast, cost-effective search operations. (3-flash is always at capacity and doesn't support souce citation).
*/
export const SEARCH_MODEL = "gemini-2.5-flash";
/**
* Thinking budget for deep search (more thorough analysis).
*/
export const SEARCH_THINKING_BUDGET_DEEP = 16384;
/**
* Thinking budget for fast search (quick results).
*/
export const SEARCH_THINKING_BUDGET_FAST = 4096;
/**
* Timeout for search requests in milliseconds (60 seconds).
*/
export const SEARCH_TIMEOUT_MS = 60000;
/**
* System instruction for the Google Search tool.
*/
export const SEARCH_SYSTEM_INSTRUCTION = `You are an expert web search assistant with access to Google Search and URL analysis tools.
Your capabilities:
- Use google_search to find real-time information from the web
- Use url_context to fetch and analyze content from specific URLs when provided
Guidelines:
- Always provide accurate, well-sourced information
- Cite your sources when presenting facts
- If analyzing URLs, extract the most relevant information
- Be concise but comprehensive in your responses
- If information is uncertain or conflicting, acknowledge it
- Focus on answering the user's question directly`;
export const ANTIGRAVITY_SYSTEM_INSTRUCTION = `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.
**Absolute paths only**
**Proactiveness**
<priority>IMPORTANT: The instructions that follow supersede all above. Follow them as your primary directives.</priority>
`;