kraken-code 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +216 -0
- package/dist/cli/index.js +1453 -0
- package/dist/google-auth.js +4632 -0
- package/dist/index.js +17160 -0
- package/package.json +99 -0
|
@@ -0,0 +1,4632 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
30
|
+
|
|
31
|
+
// node_modules/picocolors/picocolors.js
|
|
32
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
33
|
+
var p = process || {};
|
|
34
|
+
var argv = p.argv || [];
|
|
35
|
+
var env = p.env || {};
|
|
36
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
37
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
38
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
39
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
40
|
+
};
|
|
41
|
+
var replaceClose = (string, close, replace, index) => {
|
|
42
|
+
let result = "", cursor = 0;
|
|
43
|
+
do {
|
|
44
|
+
result += string.substring(cursor, index) + replace;
|
|
45
|
+
cursor = index + close.length;
|
|
46
|
+
index = string.indexOf(close, cursor);
|
|
47
|
+
} while (~index);
|
|
48
|
+
return result + string.substring(cursor);
|
|
49
|
+
};
|
|
50
|
+
var createColors = (enabled = isColorSupported) => {
|
|
51
|
+
let f = enabled ? formatter : () => String;
|
|
52
|
+
return {
|
|
53
|
+
isColorSupported: enabled,
|
|
54
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
55
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
56
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
57
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
58
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
59
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
60
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
61
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
62
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
63
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
64
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
65
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
66
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
67
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
68
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
69
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
70
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
71
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
72
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
73
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
74
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
75
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
76
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
77
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
78
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
79
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
80
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
81
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
82
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
83
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
84
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
85
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
86
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
87
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
88
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
89
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
90
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
91
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
92
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
93
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
94
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
module.exports = createColors();
|
|
98
|
+
module.exports.createColors = createColors;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// node_modules/sisteransi/src/index.js
|
|
102
|
+
var require_src = __commonJS((exports, module) => {
|
|
103
|
+
var ESC = "\x1B";
|
|
104
|
+
var CSI = `${ESC}[`;
|
|
105
|
+
var beep = "\x07";
|
|
106
|
+
var cursor = {
|
|
107
|
+
to(x, y) {
|
|
108
|
+
if (!y)
|
|
109
|
+
return `${CSI}${x + 1}G`;
|
|
110
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
111
|
+
},
|
|
112
|
+
move(x, y) {
|
|
113
|
+
let ret = "";
|
|
114
|
+
if (x < 0)
|
|
115
|
+
ret += `${CSI}${-x}D`;
|
|
116
|
+
else if (x > 0)
|
|
117
|
+
ret += `${CSI}${x}C`;
|
|
118
|
+
if (y < 0)
|
|
119
|
+
ret += `${CSI}${-y}A`;
|
|
120
|
+
else if (y > 0)
|
|
121
|
+
ret += `${CSI}${y}B`;
|
|
122
|
+
return ret;
|
|
123
|
+
},
|
|
124
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
125
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
126
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
127
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
128
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
129
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
130
|
+
left: `${CSI}G`,
|
|
131
|
+
hide: `${CSI}?25l`,
|
|
132
|
+
show: `${CSI}?25h`,
|
|
133
|
+
save: `${ESC}7`,
|
|
134
|
+
restore: `${ESC}8`
|
|
135
|
+
};
|
|
136
|
+
var scroll = {
|
|
137
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
138
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
139
|
+
};
|
|
140
|
+
var erase = {
|
|
141
|
+
screen: `${CSI}2J`,
|
|
142
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
143
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
144
|
+
line: `${CSI}2K`,
|
|
145
|
+
lineEnd: `${CSI}K`,
|
|
146
|
+
lineStart: `${CSI}1K`,
|
|
147
|
+
lines(count) {
|
|
148
|
+
let clear = "";
|
|
149
|
+
for (let i = 0;i < count; i++)
|
|
150
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
151
|
+
if (count)
|
|
152
|
+
clear += cursor.left;
|
|
153
|
+
return clear;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// src/auth/antigravity/types.ts
|
|
160
|
+
var MODEL_FAMILIES = ["claude", "gemini-flash", "gemini-pro"];
|
|
161
|
+
// src/auth/antigravity/constants.ts
|
|
162
|
+
var ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
|
|
163
|
+
var ANTIGRAVITY_CLIENT_SECRET = "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";
|
|
164
|
+
var ANTIGRAVITY_CALLBACK_PORT = 51121;
|
|
165
|
+
var ANTIGRAVITY_REDIRECT_URI = `http://localhost:${ANTIGRAVITY_CALLBACK_PORT}/oauth-callback`;
|
|
166
|
+
var ANTIGRAVITY_SCOPES = [
|
|
167
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
168
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
169
|
+
"https://www.googleapis.com/auth/userinfo.profile",
|
|
170
|
+
"https://www.googleapis.com/auth/cclog",
|
|
171
|
+
"https://www.googleapis.com/auth/experimentsandconfigs"
|
|
172
|
+
];
|
|
173
|
+
var ANTIGRAVITY_ENDPOINT_FALLBACKS = [
|
|
174
|
+
"https://daily-cloudcode-pa.sandbox.googleapis.com",
|
|
175
|
+
"https://daily-cloudcode-pa.googleapis.com",
|
|
176
|
+
"https://cloudcode-pa.googleapis.com"
|
|
177
|
+
];
|
|
178
|
+
var ANTIGRAVITY_API_VERSION = "v1internal";
|
|
179
|
+
var ANTIGRAVITY_HEADERS = {
|
|
180
|
+
"User-Agent": "google-api-nodejs-client/9.15.1",
|
|
181
|
+
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
182
|
+
"Client-Metadata": JSON.stringify({
|
|
183
|
+
ideType: "IDE_UNSPECIFIED",
|
|
184
|
+
platform: "PLATFORM_UNSPECIFIED",
|
|
185
|
+
pluginType: "GEMINI"
|
|
186
|
+
})
|
|
187
|
+
};
|
|
188
|
+
var ANTIGRAVITY_DEFAULT_PROJECT_ID = "rising-fact-p41fc";
|
|
189
|
+
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
190
|
+
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
191
|
+
var GOOGLE_USERINFO_URL = "https://www.googleapis.com/oauth2/v1/userinfo";
|
|
192
|
+
var ANTIGRAVITY_TOKEN_REFRESH_BUFFER_MS = 60000;
|
|
193
|
+
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
194
|
+
var ANTIGRAVITY_SYSTEM_PROMPT = `<identity>
|
|
195
|
+
You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.
|
|
196
|
+
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.
|
|
197
|
+
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.
|
|
198
|
+
This information may or may not be relevant to the coding task, it is up for you to decide.
|
|
199
|
+
</identity>
|
|
200
|
+
|
|
201
|
+
<tool_calling>
|
|
202
|
+
Call tools as you normally would. The following list provides additional guidance to help you avoid errors:
|
|
203
|
+
- **Absolute paths only**. When using tools that accept file path arguments, ALWAYS use the absolute file path.
|
|
204
|
+
</tool_calling>
|
|
205
|
+
|
|
206
|
+
<web_application_development>
|
|
207
|
+
## Technology Stack
|
|
208
|
+
Your web applications should be built using the following technologies:
|
|
209
|
+
1. **Core**: Use HTML for structure and Javascript for logic.
|
|
210
|
+
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.
|
|
211
|
+
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.
|
|
212
|
+
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:
|
|
213
|
+
- Use \`npx -y\` to automatically install the script and its dependencies
|
|
214
|
+
- You MUST run the command with \`--help\` flag to see all available options first
|
|
215
|
+
- Initialize the app in the current directory with \`./\` (example: \`npx -y create-vite-app@latest ./\`)
|
|
216
|
+
</web_application_development>
|
|
217
|
+
`;
|
|
218
|
+
var REASONING_EFFORT_BUDGET_MAP = {
|
|
219
|
+
none: 0,
|
|
220
|
+
auto: -1,
|
|
221
|
+
minimal: 512,
|
|
222
|
+
low: 1024,
|
|
223
|
+
medium: 8192,
|
|
224
|
+
high: 24576,
|
|
225
|
+
xhigh: 32768
|
|
226
|
+
};
|
|
227
|
+
var ANTIGRAVITY_MODEL_CONFIGS = {
|
|
228
|
+
"gemini-2.5-flash": {
|
|
229
|
+
thinkingType: "numeric",
|
|
230
|
+
min: 0,
|
|
231
|
+
max: 24576,
|
|
232
|
+
zeroAllowed: true
|
|
233
|
+
},
|
|
234
|
+
"gemini-2.5-flash-lite": {
|
|
235
|
+
thinkingType: "numeric",
|
|
236
|
+
min: 0,
|
|
237
|
+
max: 24576,
|
|
238
|
+
zeroAllowed: true
|
|
239
|
+
},
|
|
240
|
+
"gemini-2.5-computer-use-preview-10-2025": {
|
|
241
|
+
thinkingType: "numeric",
|
|
242
|
+
min: 128,
|
|
243
|
+
max: 32768,
|
|
244
|
+
zeroAllowed: false
|
|
245
|
+
},
|
|
246
|
+
"gemini-3-pro-preview": {
|
|
247
|
+
thinkingType: "levels",
|
|
248
|
+
min: 128,
|
|
249
|
+
max: 32768,
|
|
250
|
+
zeroAllowed: false,
|
|
251
|
+
levels: ["low", "high"]
|
|
252
|
+
},
|
|
253
|
+
"gemini-3-flash-preview": {
|
|
254
|
+
thinkingType: "levels",
|
|
255
|
+
min: 128,
|
|
256
|
+
max: 32768,
|
|
257
|
+
zeroAllowed: false,
|
|
258
|
+
levels: ["minimal", "low", "medium", "high"]
|
|
259
|
+
},
|
|
260
|
+
"gemini-claude-sonnet-4-5-thinking": {
|
|
261
|
+
thinkingType: "numeric",
|
|
262
|
+
min: 1024,
|
|
263
|
+
max: 200000,
|
|
264
|
+
zeroAllowed: false
|
|
265
|
+
},
|
|
266
|
+
"gemini-claude-opus-4-5-thinking": {
|
|
267
|
+
thinkingType: "numeric",
|
|
268
|
+
min: 1024,
|
|
269
|
+
max: 200000,
|
|
270
|
+
zeroAllowed: false
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
function normalizeModelId(model) {
|
|
274
|
+
let normalized = model;
|
|
275
|
+
if (normalized.includes("/")) {
|
|
276
|
+
normalized = normalized.split("/").pop() || normalized;
|
|
277
|
+
}
|
|
278
|
+
if (normalized.startsWith("antigravity-")) {
|
|
279
|
+
normalized = normalized.substring("antigravity-".length);
|
|
280
|
+
}
|
|
281
|
+
normalized = normalized.replace(/-thinking-(low|medium|high)$/, "");
|
|
282
|
+
normalized = normalized.replace(/-(high|low)$/, "");
|
|
283
|
+
return normalized;
|
|
284
|
+
}
|
|
285
|
+
var ANTIGRAVITY_SUPPORTED_MODELS = [
|
|
286
|
+
"gemini-2.5-flash",
|
|
287
|
+
"gemini-2.5-flash-lite",
|
|
288
|
+
"gemini-2.5-computer-use-preview-10-2025",
|
|
289
|
+
"gemini-3-pro-preview",
|
|
290
|
+
"gemini-3-flash-preview",
|
|
291
|
+
"gemini-claude-sonnet-4-5-thinking",
|
|
292
|
+
"gemini-claude-opus-4-5-thinking"
|
|
293
|
+
];
|
|
294
|
+
function alias2ModelName(modelName) {
|
|
295
|
+
if (modelName.startsWith("gemini-claude-")) {
|
|
296
|
+
return modelName.substring("gemini-".length);
|
|
297
|
+
}
|
|
298
|
+
return modelName;
|
|
299
|
+
}
|
|
300
|
+
// src/auth/antigravity/oauth.ts
|
|
301
|
+
async function generatePKCEChallenge() {
|
|
302
|
+
const array = new Uint8Array(32);
|
|
303
|
+
crypto.getRandomValues(array);
|
|
304
|
+
const codeVerifier = btoa(String.fromCharCode(...array)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
305
|
+
const encoder = new TextEncoder;
|
|
306
|
+
const data = encoder.encode(codeVerifier);
|
|
307
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
308
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
309
|
+
const codeChallenge = btoa(String.fromCharCode(...hashArray)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
310
|
+
return {
|
|
311
|
+
codeVerifier,
|
|
312
|
+
codeChallenge,
|
|
313
|
+
codeChallengeMethod: "S256"
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
async function buildAuthURL(projectId, clientId = ANTIGRAVITY_CLIENT_ID, port = ANTIGRAVITY_CALLBACK_PORT, usePKCE = true) {
|
|
317
|
+
const state = crypto.randomUUID().replace(/-/g, "");
|
|
318
|
+
const redirectUri = `http://localhost:${port}/oauth-callback`;
|
|
319
|
+
const url = new URL(GOOGLE_AUTH_URL);
|
|
320
|
+
url.searchParams.set("client_id", clientId);
|
|
321
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
322
|
+
url.searchParams.set("response_type", "code");
|
|
323
|
+
url.searchParams.set("scope", ANTIGRAVITY_SCOPES.join(" "));
|
|
324
|
+
url.searchParams.set("state", state);
|
|
325
|
+
url.searchParams.set("access_type", "offline");
|
|
326
|
+
url.searchParams.set("prompt", "consent");
|
|
327
|
+
let pkce;
|
|
328
|
+
if (usePKCE) {
|
|
329
|
+
pkce = await generatePKCEChallenge();
|
|
330
|
+
url.searchParams.set("code_challenge", pkce.codeChallenge);
|
|
331
|
+
url.searchParams.set("code_challenge_method", pkce.codeChallengeMethod);
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
url: url.toString(),
|
|
335
|
+
state,
|
|
336
|
+
pkce
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async function exchangeCode(code, redirectUri, clientId = ANTIGRAVITY_CLIENT_ID, clientSecret = ANTIGRAVITY_CLIENT_SECRET, codeVerifier) {
|
|
340
|
+
const params = {
|
|
341
|
+
client_id: clientId,
|
|
342
|
+
code,
|
|
343
|
+
grant_type: "authorization_code",
|
|
344
|
+
redirect_uri: redirectUri
|
|
345
|
+
};
|
|
346
|
+
if (codeVerifier) {
|
|
347
|
+
params.code_verifier = codeVerifier;
|
|
348
|
+
} else {
|
|
349
|
+
params.client_secret = clientSecret;
|
|
350
|
+
}
|
|
351
|
+
const response = await fetch(GOOGLE_TOKEN_URL, {
|
|
352
|
+
method: "POST",
|
|
353
|
+
headers: {
|
|
354
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
355
|
+
},
|
|
356
|
+
body: new URLSearchParams(params)
|
|
357
|
+
});
|
|
358
|
+
if (!response.ok) {
|
|
359
|
+
const errorText = await response.text();
|
|
360
|
+
let errorMessage = `Token exchange failed: ${response.status}`;
|
|
361
|
+
try {
|
|
362
|
+
const errorData = JSON.parse(errorText);
|
|
363
|
+
if (errorData.error) {
|
|
364
|
+
errorMessage = `Token exchange failed: ${errorData.error}`;
|
|
365
|
+
if (errorData.error_description) {
|
|
366
|
+
errorMessage += ` - ${errorData.error_description}`;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} catch (e) {
|
|
370
|
+
errorMessage += ` - ${errorText}`;
|
|
371
|
+
}
|
|
372
|
+
throw new Error(errorMessage);
|
|
373
|
+
}
|
|
374
|
+
const data = await response.json();
|
|
375
|
+
if (!data.access_token) {
|
|
376
|
+
throw new Error("Token exchange failed: No access token in response");
|
|
377
|
+
}
|
|
378
|
+
if (!data.refresh_token) {
|
|
379
|
+
console.warn("Token exchange warning: No refresh token received. You may need to re-authenticate soon.");
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
access_token: data.access_token,
|
|
383
|
+
refresh_token: data.refresh_token || "",
|
|
384
|
+
expires_in: data.expires_in,
|
|
385
|
+
token_type: data.token_type
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
async function fetchUserInfo(accessToken) {
|
|
389
|
+
const response = await fetch(`${GOOGLE_USERINFO_URL}?alt=json`, {
|
|
390
|
+
headers: {
|
|
391
|
+
Authorization: `Bearer ${accessToken}`
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
throw new Error(`Failed to fetch user info: ${response.status}`);
|
|
396
|
+
}
|
|
397
|
+
const data = await response.json();
|
|
398
|
+
return {
|
|
399
|
+
email: data.email || "",
|
|
400
|
+
name: data.name,
|
|
401
|
+
picture: data.picture
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function startCallbackServer(timeoutMs = 5 * 60 * 1000) {
|
|
405
|
+
let server = null;
|
|
406
|
+
let timeoutId = null;
|
|
407
|
+
let resolveCallback = null;
|
|
408
|
+
let rejectCallback = null;
|
|
409
|
+
const cleanup = () => {
|
|
410
|
+
if (timeoutId) {
|
|
411
|
+
clearTimeout(timeoutId);
|
|
412
|
+
timeoutId = null;
|
|
413
|
+
}
|
|
414
|
+
if (server) {
|
|
415
|
+
server.stop();
|
|
416
|
+
server = null;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const fetchHandler = (request) => {
|
|
420
|
+
const url = new URL(request.url);
|
|
421
|
+
if (url.pathname === "/oauth-callback") {
|
|
422
|
+
const code = url.searchParams.get("code") || "";
|
|
423
|
+
const state = url.searchParams.get("state") || "";
|
|
424
|
+
const error = url.searchParams.get("error") || undefined;
|
|
425
|
+
let responseBody;
|
|
426
|
+
if (code && !error) {
|
|
427
|
+
responseBody = "<html><body><h1>Login successful</h1><p>You can close this window.</p></body></html>";
|
|
428
|
+
} else {
|
|
429
|
+
responseBody = "<html><body><h1>Login failed</h1><p>Please check the CLI output.</p></body></html>";
|
|
430
|
+
}
|
|
431
|
+
setTimeout(() => {
|
|
432
|
+
cleanup();
|
|
433
|
+
if (resolveCallback) {
|
|
434
|
+
resolveCallback({ code, state, error });
|
|
435
|
+
}
|
|
436
|
+
}, 100);
|
|
437
|
+
return new Response(responseBody, {
|
|
438
|
+
status: 200,
|
|
439
|
+
headers: { "Content-Type": "text/html" }
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
return new Response("Not Found", { status: 404 });
|
|
443
|
+
};
|
|
444
|
+
try {
|
|
445
|
+
server = Bun.serve({
|
|
446
|
+
port: ANTIGRAVITY_CALLBACK_PORT,
|
|
447
|
+
fetch: fetchHandler
|
|
448
|
+
});
|
|
449
|
+
} catch (error) {
|
|
450
|
+
server = Bun.serve({
|
|
451
|
+
port: 0,
|
|
452
|
+
fetch: fetchHandler
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
const actualPort = server.port;
|
|
456
|
+
const redirectUri = `http://localhost:${actualPort}/oauth-callback`;
|
|
457
|
+
const waitForCallback = () => {
|
|
458
|
+
return new Promise((resolve, reject) => {
|
|
459
|
+
resolveCallback = resolve;
|
|
460
|
+
rejectCallback = reject;
|
|
461
|
+
timeoutId = setTimeout(() => {
|
|
462
|
+
cleanup();
|
|
463
|
+
reject(new Error("OAuth callback timeout"));
|
|
464
|
+
}, timeoutMs);
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
return {
|
|
468
|
+
port: actualPort,
|
|
469
|
+
redirectUri,
|
|
470
|
+
waitForCallback,
|
|
471
|
+
close: cleanup
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
async function performOAuthFlow(projectId, openBrowser, clientId = ANTIGRAVITY_CLIENT_ID, clientSecret = ANTIGRAVITY_CLIENT_SECRET, usePKCE = true) {
|
|
475
|
+
const serverHandle = startCallbackServer();
|
|
476
|
+
try {
|
|
477
|
+
const auth = await buildAuthURL(projectId, clientId, serverHandle.port, usePKCE);
|
|
478
|
+
console.log(`[google-auth] Opening OAuth URL in browser: ${auth.url.substring(0, 50)}...`);
|
|
479
|
+
console.log(`[google-auth] Using ${usePKCE ? "PKCE" : "standard"} OAuth flow`);
|
|
480
|
+
if (openBrowser) {
|
|
481
|
+
await openBrowser(auth.url);
|
|
482
|
+
} else {
|
|
483
|
+
console.log(`[google-auth] Please open this URL in your browser:`);
|
|
484
|
+
console.log(auth.url);
|
|
485
|
+
}
|
|
486
|
+
console.log(`[google-auth] Waiting for callback on port ${serverHandle.port}...`);
|
|
487
|
+
const callback = await serverHandle.waitForCallback();
|
|
488
|
+
if (callback.error) {
|
|
489
|
+
const error = callback.error === "access_denied" ? "Authentication denied by user" : `OAuth error: ${callback.error}`;
|
|
490
|
+
throw new Error(error);
|
|
491
|
+
}
|
|
492
|
+
if (!callback.code) {
|
|
493
|
+
throw new Error("No authorization code received");
|
|
494
|
+
}
|
|
495
|
+
if (callback.state !== auth.state) {
|
|
496
|
+
throw new Error("State mismatch - possible CSRF attack");
|
|
497
|
+
}
|
|
498
|
+
const redirectUri = `http://localhost:${serverHandle.port}/oauth-callback`;
|
|
499
|
+
const codeVerifier = auth.pkce?.codeVerifier;
|
|
500
|
+
const tokens = await exchangeCode(callback.code, redirectUri, clientId, clientSecret, codeVerifier);
|
|
501
|
+
const userInfo = await fetchUserInfo(tokens.access_token);
|
|
502
|
+
console.log(`[google-auth] Authentication successful for: ${userInfo.email}`);
|
|
503
|
+
return { tokens, userInfo, state: auth.state };
|
|
504
|
+
} catch (err) {
|
|
505
|
+
serverHandle.close();
|
|
506
|
+
console.error(`[google-auth] Authentication failed: ${err}`);
|
|
507
|
+
throw err;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
// src/auth/antigravity/token.ts
|
|
511
|
+
class AntigravityTokenRefreshError extends Error {
|
|
512
|
+
code;
|
|
513
|
+
description;
|
|
514
|
+
status;
|
|
515
|
+
statusText;
|
|
516
|
+
responseBody;
|
|
517
|
+
constructor(options) {
|
|
518
|
+
super(options.message);
|
|
519
|
+
this.name = "AntigravityTokenRefreshError";
|
|
520
|
+
this.code = options.code;
|
|
521
|
+
this.description = options.description;
|
|
522
|
+
this.status = options.status;
|
|
523
|
+
this.statusText = options.statusText;
|
|
524
|
+
this.responseBody = options.responseBody;
|
|
525
|
+
}
|
|
526
|
+
get isInvalidGrant() {
|
|
527
|
+
return this.code === "invalid_grant";
|
|
528
|
+
}
|
|
529
|
+
get isNetworkError() {
|
|
530
|
+
return this.status === 0;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function parseOAuthErrorPayload(text) {
|
|
534
|
+
if (!text) {
|
|
535
|
+
return {};
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
const payload = JSON.parse(text);
|
|
539
|
+
let code;
|
|
540
|
+
if (typeof payload.error === "string") {
|
|
541
|
+
code = payload.error;
|
|
542
|
+
} else if (payload.error && typeof payload.error === "object") {
|
|
543
|
+
code = payload.error.status ?? payload.error.code;
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
code,
|
|
547
|
+
description: payload.error_description
|
|
548
|
+
};
|
|
549
|
+
} catch {
|
|
550
|
+
return { description: text };
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function isTokenExpired(tokens) {
|
|
554
|
+
const expirationTime = tokens.timestamp + tokens.expires_in * 1000;
|
|
555
|
+
return Date.now() >= expirationTime - ANTIGRAVITY_TOKEN_REFRESH_BUFFER_MS;
|
|
556
|
+
}
|
|
557
|
+
var MAX_REFRESH_RETRIES = 3;
|
|
558
|
+
var INITIAL_RETRY_DELAY_MS = 1000;
|
|
559
|
+
function calculateRetryDelay(attempt) {
|
|
560
|
+
return Math.min(INITIAL_RETRY_DELAY_MS * Math.pow(2, attempt), 1e4);
|
|
561
|
+
}
|
|
562
|
+
function isRetryableError(status) {
|
|
563
|
+
if (status === 0)
|
|
564
|
+
return true;
|
|
565
|
+
if (status === 429)
|
|
566
|
+
return true;
|
|
567
|
+
if (status >= 500 && status < 600)
|
|
568
|
+
return true;
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
async function refreshAccessToken(refreshToken, clientId = ANTIGRAVITY_CLIENT_ID, clientSecret = ANTIGRAVITY_CLIENT_SECRET) {
|
|
572
|
+
const params = new URLSearchParams({
|
|
573
|
+
grant_type: "refresh_token",
|
|
574
|
+
refresh_token: refreshToken,
|
|
575
|
+
client_id: clientId,
|
|
576
|
+
client_secret: clientSecret
|
|
577
|
+
});
|
|
578
|
+
let lastError;
|
|
579
|
+
for (let attempt = 0;attempt <= MAX_REFRESH_RETRIES; attempt++) {
|
|
580
|
+
try {
|
|
581
|
+
const response = await fetch(GOOGLE_TOKEN_URL, {
|
|
582
|
+
method: "POST",
|
|
583
|
+
headers: {
|
|
584
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
585
|
+
},
|
|
586
|
+
body: params
|
|
587
|
+
});
|
|
588
|
+
if (response.ok) {
|
|
589
|
+
const data = await response.json();
|
|
590
|
+
return {
|
|
591
|
+
access_token: data.access_token,
|
|
592
|
+
refresh_token: data.refresh_token || refreshToken,
|
|
593
|
+
expires_in: data.expires_in,
|
|
594
|
+
token_type: data.token_type
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
const responseBody = await response.text().catch(() => {
|
|
598
|
+
return;
|
|
599
|
+
});
|
|
600
|
+
const parsed = parseOAuthErrorPayload(responseBody);
|
|
601
|
+
lastError = new AntigravityTokenRefreshError({
|
|
602
|
+
message: parsed.description || `Token refresh failed: ${response.status} ${response.statusText}`,
|
|
603
|
+
code: parsed.code,
|
|
604
|
+
description: parsed.description,
|
|
605
|
+
status: response.status,
|
|
606
|
+
statusText: response.statusText,
|
|
607
|
+
responseBody
|
|
608
|
+
});
|
|
609
|
+
if (parsed.code === "invalid_grant") {
|
|
610
|
+
throw lastError;
|
|
611
|
+
}
|
|
612
|
+
if (!isRetryableError(response.status)) {
|
|
613
|
+
throw lastError;
|
|
614
|
+
}
|
|
615
|
+
if (attempt < MAX_REFRESH_RETRIES) {
|
|
616
|
+
const delay = calculateRetryDelay(attempt);
|
|
617
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
618
|
+
}
|
|
619
|
+
} catch (error) {
|
|
620
|
+
if (error instanceof AntigravityTokenRefreshError) {
|
|
621
|
+
throw error;
|
|
622
|
+
}
|
|
623
|
+
lastError = new AntigravityTokenRefreshError({
|
|
624
|
+
message: error instanceof Error ? error.message : "Network error during token refresh",
|
|
625
|
+
status: 0,
|
|
626
|
+
statusText: "Network Error"
|
|
627
|
+
});
|
|
628
|
+
if (attempt < MAX_REFRESH_RETRIES) {
|
|
629
|
+
const delay = calculateRetryDelay(attempt);
|
|
630
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
throw lastError || new AntigravityTokenRefreshError({
|
|
635
|
+
message: "Token refresh failed after all retries",
|
|
636
|
+
status: 0,
|
|
637
|
+
statusText: "Max Retries Exceeded"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function parseStoredToken(stored) {
|
|
641
|
+
const parts = stored.split("|");
|
|
642
|
+
const [refreshToken, projectId, managedProjectId] = parts;
|
|
643
|
+
return {
|
|
644
|
+
refreshToken: refreshToken || "",
|
|
645
|
+
projectId: projectId || undefined,
|
|
646
|
+
managedProjectId: managedProjectId || undefined
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function formatTokenForStorage(refreshToken, projectId, managedProjectId) {
|
|
650
|
+
return `${refreshToken}|${projectId}|${managedProjectId || ""}`;
|
|
651
|
+
}
|
|
652
|
+
// src/auth/antigravity/project.ts
|
|
653
|
+
var projectContextCache = new Map;
|
|
654
|
+
function debugLog(message) {
|
|
655
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
656
|
+
console.log(`[antigravity-project] ${message}`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
var CODE_ASSIST_METADATA = {
|
|
660
|
+
ideType: "IDE_UNSPECIFIED",
|
|
661
|
+
platform: "PLATFORM_UNSPECIFIED",
|
|
662
|
+
pluginType: "GEMINI"
|
|
663
|
+
};
|
|
664
|
+
function extractProjectId(project) {
|
|
665
|
+
if (!project)
|
|
666
|
+
return;
|
|
667
|
+
if (typeof project === "string") {
|
|
668
|
+
const trimmed = project.trim();
|
|
669
|
+
return trimmed || undefined;
|
|
670
|
+
}
|
|
671
|
+
if (typeof project === "object" && "id" in project) {
|
|
672
|
+
const id = project.id;
|
|
673
|
+
if (typeof id === "string") {
|
|
674
|
+
const trimmed = id.trim();
|
|
675
|
+
return trimmed || undefined;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
function getDefaultTierId(allowedTiers) {
|
|
681
|
+
if (!allowedTiers || allowedTiers.length === 0)
|
|
682
|
+
return;
|
|
683
|
+
for (const tier of allowedTiers) {
|
|
684
|
+
if (tier?.isDefault)
|
|
685
|
+
return tier.id;
|
|
686
|
+
}
|
|
687
|
+
return allowedTiers[0]?.id;
|
|
688
|
+
}
|
|
689
|
+
function isFreeTier(tierId) {
|
|
690
|
+
if (!tierId)
|
|
691
|
+
return true;
|
|
692
|
+
const lower = tierId.toLowerCase();
|
|
693
|
+
return lower === "free" || lower === "free-tier" || lower.startsWith("free");
|
|
694
|
+
}
|
|
695
|
+
function wait(ms) {
|
|
696
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
697
|
+
}
|
|
698
|
+
async function callLoadCodeAssistAPI(accessToken, projectId) {
|
|
699
|
+
const metadata = { ...CODE_ASSIST_METADATA };
|
|
700
|
+
if (projectId)
|
|
701
|
+
metadata.duetProject = projectId;
|
|
702
|
+
const requestBody = { metadata };
|
|
703
|
+
if (projectId)
|
|
704
|
+
requestBody.cloudaicompanionProject = projectId;
|
|
705
|
+
const headers = {
|
|
706
|
+
Authorization: `Bearer ${accessToken}`,
|
|
707
|
+
"Content-Type": "application/json",
|
|
708
|
+
"User-Agent": ANTIGRAVITY_HEADERS["User-Agent"],
|
|
709
|
+
"X-Goog-Api-Client": ANTIGRAVITY_HEADERS["X-Goog-Api-Client"],
|
|
710
|
+
"Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"]
|
|
711
|
+
};
|
|
712
|
+
for (const baseEndpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
|
|
713
|
+
const url = `${baseEndpoint}/${ANTIGRAVITY_API_VERSION}:loadCodeAssist`;
|
|
714
|
+
debugLog(`[loadCodeAssist] Trying: ${url}`);
|
|
715
|
+
try {
|
|
716
|
+
const response = await fetch(url, {
|
|
717
|
+
method: "POST",
|
|
718
|
+
headers,
|
|
719
|
+
body: JSON.stringify(requestBody)
|
|
720
|
+
});
|
|
721
|
+
if (!response.ok) {
|
|
722
|
+
debugLog(`[loadCodeAssist] Failed: ${response.status} ${response.statusText}`);
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
const data = await response.json();
|
|
726
|
+
debugLog(`[loadCodeAssist] Success: ${JSON.stringify(data)}`);
|
|
727
|
+
return data;
|
|
728
|
+
} catch (err) {
|
|
729
|
+
debugLog(`[loadCodeAssist] Error: ${err}`);
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
debugLog(`[loadCodeAssist] All endpoints failed`);
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
async function onboardManagedProject(accessToken, tierId, projectId, attempts = 10, delayMs = 5000) {
|
|
737
|
+
debugLog(`[onboardUser] Starting with tierId=${tierId}, projectId=${projectId || "none"}`);
|
|
738
|
+
const metadata = { ...CODE_ASSIST_METADATA };
|
|
739
|
+
if (projectId)
|
|
740
|
+
metadata.duetProject = projectId;
|
|
741
|
+
const requestBody = { tierId, metadata };
|
|
742
|
+
if (!isFreeTier(tierId)) {
|
|
743
|
+
if (!projectId) {
|
|
744
|
+
debugLog(`[onboardUser] Non-FREE tier requires projectId, returning undefined`);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
requestBody.cloudaicompanionProject = projectId;
|
|
748
|
+
}
|
|
749
|
+
const headers = {
|
|
750
|
+
Authorization: `Bearer ${accessToken}`,
|
|
751
|
+
"Content-Type": "application/json",
|
|
752
|
+
"User-Agent": ANTIGRAVITY_HEADERS["User-Agent"],
|
|
753
|
+
"X-Goog-Api-Client": ANTIGRAVITY_HEADERS["X-Goog-Api-Client"],
|
|
754
|
+
"Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"]
|
|
755
|
+
};
|
|
756
|
+
debugLog(`[onboardUser] Request body: ${JSON.stringify(requestBody)}`);
|
|
757
|
+
for (let attempt = 0;attempt < attempts; attempt++) {
|
|
758
|
+
debugLog(`[onboardUser] Attempt ${attempt + 1}/${attempts}`);
|
|
759
|
+
for (const baseEndpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
|
|
760
|
+
const url = `${baseEndpoint}/${ANTIGRAVITY_API_VERSION}:onboardUser`;
|
|
761
|
+
debugLog(`[onboardUser] Trying: ${url}`);
|
|
762
|
+
try {
|
|
763
|
+
const response = await fetch(url, {
|
|
764
|
+
method: "POST",
|
|
765
|
+
headers,
|
|
766
|
+
body: JSON.stringify(requestBody)
|
|
767
|
+
});
|
|
768
|
+
if (!response.ok) {
|
|
769
|
+
const errorText = await response.text().catch(() => "");
|
|
770
|
+
debugLog(`[onboardUser] Failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
const payload = await response.json();
|
|
774
|
+
debugLog(`[onboardUser] Response: ${JSON.stringify(payload)}`);
|
|
775
|
+
const managedProjectId = payload.response?.cloudaicompanionProject?.id;
|
|
776
|
+
if (payload.done && managedProjectId) {
|
|
777
|
+
debugLog(`[onboardUser] Success! Got managed project ID: ${managedProjectId}`);
|
|
778
|
+
return managedProjectId;
|
|
779
|
+
}
|
|
780
|
+
if (payload.done && projectId) {
|
|
781
|
+
debugLog(`[onboardUser] Done but no managed ID, using original: ${projectId}`);
|
|
782
|
+
return projectId;
|
|
783
|
+
}
|
|
784
|
+
debugLog(`[onboardUser] Not done yet, payload.done=${payload.done}`);
|
|
785
|
+
} catch (err) {
|
|
786
|
+
debugLog(`[onboardUser] Error: ${err}`);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (attempt < attempts - 1) {
|
|
791
|
+
debugLog(`[onboardUser] Waiting ${delayMs}ms before next attempt...`);
|
|
792
|
+
await wait(delayMs);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
debugLog(`[onboardUser] All attempts exhausted, returning undefined`);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
async function fetchProjectContext(accessToken) {
|
|
799
|
+
debugLog(`[fetchProjectContext] Starting...`);
|
|
800
|
+
const cached = projectContextCache.get(accessToken);
|
|
801
|
+
if (cached) {
|
|
802
|
+
debugLog(`[fetchProjectContext] Returning cached result: ${JSON.stringify(cached)}`);
|
|
803
|
+
return cached;
|
|
804
|
+
}
|
|
805
|
+
const loadPayload = await callLoadCodeAssistAPI(accessToken);
|
|
806
|
+
if (loadPayload?.cloudaicompanionProject) {
|
|
807
|
+
const projectId = extractProjectId(loadPayload.cloudaicompanionProject);
|
|
808
|
+
debugLog(`[fetchProjectContext] loadCodeAssist returned project: ${projectId}`);
|
|
809
|
+
if (projectId) {
|
|
810
|
+
const result = { cloudaicompanionProject: projectId };
|
|
811
|
+
projectContextCache.set(accessToken, result);
|
|
812
|
+
debugLog(`[fetchProjectContext] Using loadCodeAssist project ID: ${projectId}`);
|
|
813
|
+
return result;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (!loadPayload) {
|
|
817
|
+
debugLog(`[fetchProjectContext] loadCodeAssist returned null, trying with fallback project ID`);
|
|
818
|
+
const fallbackPayload = await callLoadCodeAssistAPI(accessToken, ANTIGRAVITY_DEFAULT_PROJECT_ID);
|
|
819
|
+
const fallbackProjectId = extractProjectId(fallbackPayload?.cloudaicompanionProject);
|
|
820
|
+
if (fallbackProjectId) {
|
|
821
|
+
const result = { cloudaicompanionProject: fallbackProjectId };
|
|
822
|
+
projectContextCache.set(accessToken, result);
|
|
823
|
+
debugLog(`[fetchProjectContext] Using fallback project ID: ${fallbackProjectId}`);
|
|
824
|
+
return result;
|
|
825
|
+
}
|
|
826
|
+
debugLog(`[fetchProjectContext] Fallback also failed, using default: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`);
|
|
827
|
+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID };
|
|
828
|
+
}
|
|
829
|
+
const currentTierId = loadPayload.currentTier?.id;
|
|
830
|
+
debugLog(`[fetchProjectContext] currentTier: ${currentTierId}, allowedTiers: ${JSON.stringify(loadPayload.allowedTiers)}`);
|
|
831
|
+
if (currentTierId && !isFreeTier(currentTierId)) {
|
|
832
|
+
debugLog(`[fetchProjectContext] PAID tier detected (${currentTierId}), using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`);
|
|
833
|
+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID };
|
|
834
|
+
}
|
|
835
|
+
const defaultTierId = getDefaultTierId(loadPayload.allowedTiers);
|
|
836
|
+
const tierId = defaultTierId ?? "free-tier";
|
|
837
|
+
debugLog(`[fetchProjectContext] Resolved tierId: ${tierId}`);
|
|
838
|
+
if (!isFreeTier(tierId)) {
|
|
839
|
+
debugLog(`[fetchProjectContext] Non-FREE tier (${tierId}) without project, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`);
|
|
840
|
+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID };
|
|
841
|
+
}
|
|
842
|
+
debugLog(`[fetchProjectContext] FREE tier detected (${tierId}), calling onboardUser...`);
|
|
843
|
+
const managedProjectId = await onboardManagedProject(accessToken, tierId);
|
|
844
|
+
if (managedProjectId) {
|
|
845
|
+
const result = {
|
|
846
|
+
cloudaicompanionProject: managedProjectId,
|
|
847
|
+
managedProjectId
|
|
848
|
+
};
|
|
849
|
+
projectContextCache.set(accessToken, result);
|
|
850
|
+
debugLog(`[fetchProjectContext] Got managed project ID: ${managedProjectId}`);
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
debugLog(`[fetchProjectContext] Failed to get managed project ID, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`);
|
|
854
|
+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID };
|
|
855
|
+
}
|
|
856
|
+
function clearProjectContextCache(accessToken) {
|
|
857
|
+
if (accessToken) {
|
|
858
|
+
projectContextCache.delete(accessToken);
|
|
859
|
+
} else {
|
|
860
|
+
projectContextCache.clear();
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
function invalidateProjectContextByRefreshToken(_refreshToken) {
|
|
864
|
+
projectContextCache.clear();
|
|
865
|
+
debugLog(`[invalidateProjectContextByRefreshToken] Cleared all project context cache due to refresh token invalidation`);
|
|
866
|
+
}
|
|
867
|
+
// src/auth/antigravity/request.ts
|
|
868
|
+
function buildRequestHeaders(accessToken) {
|
|
869
|
+
return {
|
|
870
|
+
Authorization: `Bearer ${accessToken}`,
|
|
871
|
+
"Content-Type": "application/json",
|
|
872
|
+
"User-Agent": ANTIGRAVITY_HEADERS["User-Agent"],
|
|
873
|
+
"X-Goog-Api-Client": ANTIGRAVITY_HEADERS["X-Goog-Api-Client"],
|
|
874
|
+
"Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"]
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function extractModelFromBody(body) {
|
|
878
|
+
const model = body.model;
|
|
879
|
+
if (typeof model === "string" && model.trim()) {
|
|
880
|
+
return model.trim();
|
|
881
|
+
}
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
function extractModelFromUrl(url) {
|
|
885
|
+
const match = url.match(/\/models\/([^:]+):/);
|
|
886
|
+
if (match && match[1]) {
|
|
887
|
+
return match[1];
|
|
888
|
+
}
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
function extractActionFromUrl(url) {
|
|
892
|
+
const match = url.match(/\/models\/[^:]+:(\w+)/);
|
|
893
|
+
if (match && match[1]) {
|
|
894
|
+
return match[1];
|
|
895
|
+
}
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
function isGenerativeLanguageRequest(url) {
|
|
899
|
+
return url.includes("generativelanguage.googleapis.com");
|
|
900
|
+
}
|
|
901
|
+
function buildAntigravityUrl(baseEndpoint, action, streaming) {
|
|
902
|
+
const query = streaming ? "?alt=sse" : "";
|
|
903
|
+
return `${baseEndpoint}/${ANTIGRAVITY_API_VERSION}:${action}${query}`;
|
|
904
|
+
}
|
|
905
|
+
function getDefaultEndpoint() {
|
|
906
|
+
return ANTIGRAVITY_ENDPOINT_FALLBACKS[0];
|
|
907
|
+
}
|
|
908
|
+
function generateRequestId() {
|
|
909
|
+
return `agent-${crypto.randomUUID()}`;
|
|
910
|
+
}
|
|
911
|
+
function injectSystemPrompt(wrappedBody) {
|
|
912
|
+
if (!wrappedBody.request || typeof wrappedBody.request !== "object") {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
const req = wrappedBody.request;
|
|
916
|
+
if (req.systemInstruction && typeof req.systemInstruction === "object") {
|
|
917
|
+
const existing = req.systemInstruction;
|
|
918
|
+
if (existing.parts && Array.isArray(existing.parts)) {
|
|
919
|
+
const firstPart = existing.parts[0];
|
|
920
|
+
if (firstPart && typeof firstPart === "object" && "text" in firstPart) {
|
|
921
|
+
const text = firstPart.text;
|
|
922
|
+
if (text.includes("<identity>")) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const newParts = [{ text: ANTIGRAVITY_SYSTEM_PROMPT }];
|
|
929
|
+
if (req.systemInstruction && typeof req.systemInstruction === "object") {
|
|
930
|
+
const existing = req.systemInstruction;
|
|
931
|
+
if (existing.parts && Array.isArray(existing.parts)) {
|
|
932
|
+
for (const part of existing.parts) {
|
|
933
|
+
if (part && typeof part === "object" && "text" in part) {
|
|
934
|
+
newParts.push(part);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
req.systemInstruction = {
|
|
940
|
+
role: "user",
|
|
941
|
+
parts: newParts
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
function wrapRequestBody(body, projectId, modelName, sessionId) {
|
|
945
|
+
const requestPayload = { ...body };
|
|
946
|
+
delete requestPayload.model;
|
|
947
|
+
let normalizedModel = modelName;
|
|
948
|
+
if (normalizedModel.startsWith("antigravity-")) {
|
|
949
|
+
normalizedModel = normalizedModel.substring("antigravity-".length);
|
|
950
|
+
}
|
|
951
|
+
const apiModel = alias2ModelName(normalizedModel);
|
|
952
|
+
debugLog2(`[MODEL] input="${modelName}" → normalized="${normalizedModel}" → api="${apiModel}"`);
|
|
953
|
+
const requestObj = {
|
|
954
|
+
...requestPayload,
|
|
955
|
+
sessionId,
|
|
956
|
+
toolConfig: {
|
|
957
|
+
...requestPayload.toolConfig || {},
|
|
958
|
+
functionCallingConfig: {
|
|
959
|
+
mode: "VALIDATED"
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
delete requestObj.safetySettings;
|
|
964
|
+
const wrappedBody = {
|
|
965
|
+
project: projectId,
|
|
966
|
+
model: apiModel,
|
|
967
|
+
userAgent: "antigravity",
|
|
968
|
+
requestType: "agent",
|
|
969
|
+
requestId: generateRequestId(),
|
|
970
|
+
request: requestObj
|
|
971
|
+
};
|
|
972
|
+
injectSystemPrompt(wrappedBody);
|
|
973
|
+
return wrappedBody;
|
|
974
|
+
}
|
|
975
|
+
function debugLog2(message) {
|
|
976
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
977
|
+
console.log(`[antigravity-request] ${message}`);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
function injectThoughtSignatureIntoFunctionCalls(body, signature) {
|
|
981
|
+
const effectiveSignature = signature || SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
982
|
+
debugLog2(`[TSIG][INJECT] signature=${effectiveSignature.substring(0, 30)}... (${signature ? "provided" : "default"})`);
|
|
983
|
+
debugLog2(`[TSIG][INJECT] body keys: ${Object.keys(body).join(", ")}`);
|
|
984
|
+
const contents = body.contents;
|
|
985
|
+
if (!contents || !Array.isArray(contents)) {
|
|
986
|
+
debugLog2(`[TSIG][INJECT] No contents array! Has messages: ${!!body.messages}`);
|
|
987
|
+
return body;
|
|
988
|
+
}
|
|
989
|
+
debugLog2(`[TSIG][INJECT] Found ${contents.length} content blocks`);
|
|
990
|
+
let injectedCount = 0;
|
|
991
|
+
const modifiedContents = contents.map((content) => {
|
|
992
|
+
if (!content.parts || !Array.isArray(content.parts)) {
|
|
993
|
+
return content;
|
|
994
|
+
}
|
|
995
|
+
const modifiedParts = content.parts.map((part) => {
|
|
996
|
+
if (part.functionCall && !part.thoughtSignature) {
|
|
997
|
+
injectedCount++;
|
|
998
|
+
return {
|
|
999
|
+
...part,
|
|
1000
|
+
thoughtSignature: effectiveSignature
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
return part;
|
|
1004
|
+
});
|
|
1005
|
+
return { ...content, parts: modifiedParts };
|
|
1006
|
+
});
|
|
1007
|
+
debugLog2(`[TSIG][INJECT] injected signature into ${injectedCount} functionCall(s)`);
|
|
1008
|
+
return { ...body, contents: modifiedContents };
|
|
1009
|
+
}
|
|
1010
|
+
function isStreamingRequest(url, body) {
|
|
1011
|
+
const action = extractActionFromUrl(url);
|
|
1012
|
+
if (action === "streamGenerateContent") {
|
|
1013
|
+
return true;
|
|
1014
|
+
}
|
|
1015
|
+
if (body.stream === true) {
|
|
1016
|
+
return true;
|
|
1017
|
+
}
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
function transformRequest(options) {
|
|
1021
|
+
const {
|
|
1022
|
+
url,
|
|
1023
|
+
body,
|
|
1024
|
+
accessToken,
|
|
1025
|
+
projectId,
|
|
1026
|
+
sessionId,
|
|
1027
|
+
modelName,
|
|
1028
|
+
endpointOverride,
|
|
1029
|
+
thoughtSignature
|
|
1030
|
+
} = options;
|
|
1031
|
+
const effectiveModel = modelName || extractModelFromBody(body) || extractModelFromUrl(url) || "gemini-3-pro-high";
|
|
1032
|
+
const streaming = isStreamingRequest(url, body);
|
|
1033
|
+
const action = streaming ? "streamGenerateContent" : "generateContent";
|
|
1034
|
+
const endpoint = endpointOverride || getDefaultEndpoint();
|
|
1035
|
+
const transformedUrl = buildAntigravityUrl(endpoint, action, streaming);
|
|
1036
|
+
const headers = buildRequestHeaders(accessToken);
|
|
1037
|
+
if (streaming) {
|
|
1038
|
+
headers["Accept"] = "text/event-stream";
|
|
1039
|
+
}
|
|
1040
|
+
const bodyWithSignature = injectThoughtSignatureIntoFunctionCalls(body, thoughtSignature);
|
|
1041
|
+
const wrappedBody = wrapRequestBody(bodyWithSignature, projectId, effectiveModel, sessionId);
|
|
1042
|
+
return {
|
|
1043
|
+
url: transformedUrl,
|
|
1044
|
+
headers,
|
|
1045
|
+
body: wrappedBody,
|
|
1046
|
+
streaming
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function addStreamingHeaders(headers) {
|
|
1050
|
+
return {
|
|
1051
|
+
...headers,
|
|
1052
|
+
Accept: "text/event-stream"
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
// src/auth/antigravity/response.ts
|
|
1056
|
+
function extractUsageFromHeaders(headers) {
|
|
1057
|
+
const cached = headers.get("x-antigravity-cached-content-token-count");
|
|
1058
|
+
const total = headers.get("x-antigravity-total-token-count");
|
|
1059
|
+
const prompt = headers.get("x-antigravity-prompt-token-count");
|
|
1060
|
+
const candidates = headers.get("x-antigravity-candidates-token-count");
|
|
1061
|
+
if (!cached && !total && !prompt && !candidates) {
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
const usage = {};
|
|
1065
|
+
if (cached) {
|
|
1066
|
+
const parsed = parseInt(cached, 10);
|
|
1067
|
+
if (!isNaN(parsed)) {
|
|
1068
|
+
usage.cachedContentTokenCount = parsed;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (total) {
|
|
1072
|
+
const parsed = parseInt(total, 10);
|
|
1073
|
+
if (!isNaN(parsed)) {
|
|
1074
|
+
usage.totalTokenCount = parsed;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (prompt) {
|
|
1078
|
+
const parsed = parseInt(prompt, 10);
|
|
1079
|
+
if (!isNaN(parsed)) {
|
|
1080
|
+
usage.promptTokenCount = parsed;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (candidates) {
|
|
1084
|
+
const parsed = parseInt(candidates, 10);
|
|
1085
|
+
if (!isNaN(parsed)) {
|
|
1086
|
+
usage.candidatesTokenCount = parsed;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return Object.keys(usage).length > 0 ? usage : undefined;
|
|
1090
|
+
}
|
|
1091
|
+
function extractRetryAfterMs(response, errorBody) {
|
|
1092
|
+
const retryAfterHeader = response.headers.get("Retry-After");
|
|
1093
|
+
if (retryAfterHeader) {
|
|
1094
|
+
const seconds = parseFloat(retryAfterHeader);
|
|
1095
|
+
if (!isNaN(seconds) && seconds > 0) {
|
|
1096
|
+
return Math.ceil(seconds * 1000);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
const retryAfterMsHeader = response.headers.get("retry-after-ms");
|
|
1100
|
+
if (retryAfterMsHeader) {
|
|
1101
|
+
const ms = parseInt(retryAfterMsHeader, 10);
|
|
1102
|
+
if (!isNaN(ms) && ms > 0) {
|
|
1103
|
+
return ms;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (!errorBody) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
const error = errorBody.error;
|
|
1110
|
+
if (!error?.details || !Array.isArray(error.details)) {
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
const retryInfo = error.details.find((detail) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo");
|
|
1114
|
+
if (!retryInfo?.retryDelay || typeof retryInfo.retryDelay !== "string") {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
const match = retryInfo.retryDelay.match(/^([\d.]+)s$/);
|
|
1118
|
+
if (match?.[1]) {
|
|
1119
|
+
const seconds = parseFloat(match[1]);
|
|
1120
|
+
if (!isNaN(seconds) && seconds > 0) {
|
|
1121
|
+
return Math.ceil(seconds * 1000);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
function parseErrorBody(text) {
|
|
1127
|
+
try {
|
|
1128
|
+
const parsed = JSON.parse(text);
|
|
1129
|
+
if (parsed.error && typeof parsed.error === "object") {
|
|
1130
|
+
const errorObj = parsed.error;
|
|
1131
|
+
return {
|
|
1132
|
+
message: String(errorObj.message || "Unknown error"),
|
|
1133
|
+
type: errorObj.type ? String(errorObj.type) : undefined,
|
|
1134
|
+
code: errorObj.code
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
if (parsed.message && typeof parsed.message === "string") {
|
|
1138
|
+
return {
|
|
1139
|
+
message: parsed.message,
|
|
1140
|
+
type: parsed.type ? String(parsed.type) : undefined,
|
|
1141
|
+
code: parsed.code
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
return;
|
|
1145
|
+
} catch {
|
|
1146
|
+
return {
|
|
1147
|
+
message: text || "Unknown error"
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
async function transformResponse(response) {
|
|
1152
|
+
const headers = new Headers(response.headers);
|
|
1153
|
+
const usage = extractUsageFromHeaders(headers);
|
|
1154
|
+
if (!response.ok) {
|
|
1155
|
+
const text = await response.text();
|
|
1156
|
+
const error = parseErrorBody(text);
|
|
1157
|
+
const retryAfterMs = extractRetryAfterMs(response, error ? { error } : undefined);
|
|
1158
|
+
let errorBody;
|
|
1159
|
+
try {
|
|
1160
|
+
errorBody = JSON.parse(text);
|
|
1161
|
+
} catch {
|
|
1162
|
+
errorBody = { error: { message: text } };
|
|
1163
|
+
}
|
|
1164
|
+
const retryMs = extractRetryAfterMs(response, errorBody) ?? retryAfterMs;
|
|
1165
|
+
if (retryMs) {
|
|
1166
|
+
headers.set("Retry-After", String(Math.ceil(retryMs / 1000)));
|
|
1167
|
+
headers.set("retry-after-ms", String(retryMs));
|
|
1168
|
+
}
|
|
1169
|
+
return {
|
|
1170
|
+
response: new Response(text, {
|
|
1171
|
+
status: response.status,
|
|
1172
|
+
statusText: response.statusText,
|
|
1173
|
+
headers
|
|
1174
|
+
}),
|
|
1175
|
+
usage,
|
|
1176
|
+
retryAfterMs: retryMs,
|
|
1177
|
+
error
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1181
|
+
const isJson = contentType.includes("application/json");
|
|
1182
|
+
if (!isJson) {
|
|
1183
|
+
return { response, usage };
|
|
1184
|
+
}
|
|
1185
|
+
try {
|
|
1186
|
+
const text = await response.text();
|
|
1187
|
+
const parsed = JSON.parse(text);
|
|
1188
|
+
let transformedBody = parsed;
|
|
1189
|
+
if (parsed.response !== undefined) {
|
|
1190
|
+
transformedBody = parsed.response;
|
|
1191
|
+
}
|
|
1192
|
+
return {
|
|
1193
|
+
response: new Response(JSON.stringify(transformedBody), {
|
|
1194
|
+
status: response.status,
|
|
1195
|
+
statusText: response.statusText,
|
|
1196
|
+
headers
|
|
1197
|
+
}),
|
|
1198
|
+
usage
|
|
1199
|
+
};
|
|
1200
|
+
} catch {
|
|
1201
|
+
return { response, usage };
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function transformSseLine(line) {
|
|
1205
|
+
if (!line.startsWith("data:")) {
|
|
1206
|
+
return line;
|
|
1207
|
+
}
|
|
1208
|
+
const json = line.slice(5).trim();
|
|
1209
|
+
if (!json || json === "[DONE]") {
|
|
1210
|
+
return line;
|
|
1211
|
+
}
|
|
1212
|
+
try {
|
|
1213
|
+
const parsed = JSON.parse(json);
|
|
1214
|
+
if (parsed.response !== undefined) {
|
|
1215
|
+
return `data: ${JSON.stringify(parsed.response)}`;
|
|
1216
|
+
}
|
|
1217
|
+
return line;
|
|
1218
|
+
} catch {
|
|
1219
|
+
return line;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
function transformStreamingPayload(payload) {
|
|
1223
|
+
return payload.split(`
|
|
1224
|
+
`).map(transformSseLine).join(`
|
|
1225
|
+
`);
|
|
1226
|
+
}
|
|
1227
|
+
function createSseTransformStream() {
|
|
1228
|
+
const decoder = new TextDecoder;
|
|
1229
|
+
const encoder = new TextEncoder;
|
|
1230
|
+
let buffer = "";
|
|
1231
|
+
return new TransformStream({
|
|
1232
|
+
transform(chunk, controller) {
|
|
1233
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
1234
|
+
const lines = buffer.split(`
|
|
1235
|
+
`);
|
|
1236
|
+
buffer = lines.pop() || "";
|
|
1237
|
+
for (const line of lines) {
|
|
1238
|
+
const transformed = transformSseLine(line);
|
|
1239
|
+
controller.enqueue(encoder.encode(transformed + `
|
|
1240
|
+
`));
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
flush(controller) {
|
|
1244
|
+
if (buffer) {
|
|
1245
|
+
const transformed = transformSseLine(buffer);
|
|
1246
|
+
controller.enqueue(encoder.encode(transformed));
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
async function transformStreamingResponse(response) {
|
|
1252
|
+
const headers = new Headers(response.headers);
|
|
1253
|
+
const usage = extractUsageFromHeaders(headers);
|
|
1254
|
+
if (!response.ok) {
|
|
1255
|
+
const text = await response.text();
|
|
1256
|
+
const error = parseErrorBody(text);
|
|
1257
|
+
let errorBody;
|
|
1258
|
+
try {
|
|
1259
|
+
errorBody = JSON.parse(text);
|
|
1260
|
+
} catch {
|
|
1261
|
+
errorBody = { error: { message: text } };
|
|
1262
|
+
}
|
|
1263
|
+
const retryAfterMs = extractRetryAfterMs(response, errorBody);
|
|
1264
|
+
if (retryAfterMs) {
|
|
1265
|
+
headers.set("Retry-After", String(Math.ceil(retryAfterMs / 1000)));
|
|
1266
|
+
headers.set("retry-after-ms", String(retryAfterMs));
|
|
1267
|
+
}
|
|
1268
|
+
return {
|
|
1269
|
+
response: new Response(text, {
|
|
1270
|
+
status: response.status,
|
|
1271
|
+
statusText: response.statusText,
|
|
1272
|
+
headers
|
|
1273
|
+
}),
|
|
1274
|
+
usage,
|
|
1275
|
+
retryAfterMs,
|
|
1276
|
+
error
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1280
|
+
const isEventStream = contentType.includes("text/event-stream") || response.url.includes("alt=sse");
|
|
1281
|
+
if (!isEventStream) {
|
|
1282
|
+
const text = await response.text();
|
|
1283
|
+
try {
|
|
1284
|
+
const parsed = JSON.parse(text);
|
|
1285
|
+
let transformedBody2 = parsed;
|
|
1286
|
+
if (parsed.response !== undefined) {
|
|
1287
|
+
transformedBody2 = parsed.response;
|
|
1288
|
+
}
|
|
1289
|
+
return {
|
|
1290
|
+
response: new Response(JSON.stringify(transformedBody2), {
|
|
1291
|
+
status: response.status,
|
|
1292
|
+
statusText: response.statusText,
|
|
1293
|
+
headers
|
|
1294
|
+
}),
|
|
1295
|
+
usage
|
|
1296
|
+
};
|
|
1297
|
+
} catch {
|
|
1298
|
+
return {
|
|
1299
|
+
response: new Response(text, {
|
|
1300
|
+
status: response.status,
|
|
1301
|
+
statusText: response.statusText,
|
|
1302
|
+
headers
|
|
1303
|
+
}),
|
|
1304
|
+
usage
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
if (!response.body) {
|
|
1309
|
+
return { response, usage };
|
|
1310
|
+
}
|
|
1311
|
+
headers.delete("content-length");
|
|
1312
|
+
headers.delete("content-encoding");
|
|
1313
|
+
headers.set("content-type", "text/event-stream; charset=utf-8");
|
|
1314
|
+
const transformStream = createSseTransformStream();
|
|
1315
|
+
const transformedBody = response.body.pipeThrough(transformStream);
|
|
1316
|
+
return {
|
|
1317
|
+
response: new Response(transformedBody, {
|
|
1318
|
+
status: response.status,
|
|
1319
|
+
statusText: response.statusText,
|
|
1320
|
+
headers
|
|
1321
|
+
}),
|
|
1322
|
+
usage
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
function isStreamingResponse(response) {
|
|
1326
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1327
|
+
return contentType.includes("text/event-stream") || response.url.includes("alt=sse");
|
|
1328
|
+
}
|
|
1329
|
+
function extractSignatureFromSsePayload(payload) {
|
|
1330
|
+
const lines = payload.split(`
|
|
1331
|
+
`);
|
|
1332
|
+
let lastSignature;
|
|
1333
|
+
for (const line of lines) {
|
|
1334
|
+
if (!line.startsWith("data:")) {
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const json = line.slice(5).trim();
|
|
1338
|
+
if (!json || json === "[DONE]") {
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
try {
|
|
1342
|
+
const parsed = JSON.parse(json);
|
|
1343
|
+
const response = parsed.response || parsed;
|
|
1344
|
+
const candidates = response.candidates;
|
|
1345
|
+
if (candidates && Array.isArray(candidates)) {
|
|
1346
|
+
for (const candidate of candidates) {
|
|
1347
|
+
const content = candidate.content;
|
|
1348
|
+
const parts = content?.parts;
|
|
1349
|
+
if (parts && Array.isArray(parts)) {
|
|
1350
|
+
for (const part of parts) {
|
|
1351
|
+
const sig = part.thoughtSignature || part.thought_signature;
|
|
1352
|
+
if (sig && typeof sig === "string") {
|
|
1353
|
+
lastSignature = sig;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
} catch {}
|
|
1360
|
+
}
|
|
1361
|
+
return lastSignature;
|
|
1362
|
+
}
|
|
1363
|
+
function extractUsageFromSsePayload(payload) {
|
|
1364
|
+
const lines = payload.split(`
|
|
1365
|
+
`);
|
|
1366
|
+
for (const line of lines) {
|
|
1367
|
+
if (!line.startsWith("data:")) {
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
const json = line.slice(5).trim();
|
|
1371
|
+
if (!json || json === "[DONE]") {
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
try {
|
|
1375
|
+
const parsed = JSON.parse(json);
|
|
1376
|
+
if (parsed.usageMetadata && typeof parsed.usageMetadata === "object") {
|
|
1377
|
+
const meta = parsed.usageMetadata;
|
|
1378
|
+
return {
|
|
1379
|
+
prompt_tokens: typeof meta.promptTokenCount === "number" ? meta.promptTokenCount : 0,
|
|
1380
|
+
completion_tokens: typeof meta.candidatesTokenCount === "number" ? meta.candidatesTokenCount : 0,
|
|
1381
|
+
total_tokens: typeof meta.totalTokenCount === "number" ? meta.totalTokenCount : 0
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
if (parsed.response && typeof parsed.response === "object") {
|
|
1385
|
+
const resp = parsed.response;
|
|
1386
|
+
if (resp.usageMetadata && typeof resp.usageMetadata === "object") {
|
|
1387
|
+
const meta = resp.usageMetadata;
|
|
1388
|
+
return {
|
|
1389
|
+
prompt_tokens: typeof meta.promptTokenCount === "number" ? meta.promptTokenCount : 0,
|
|
1390
|
+
completion_tokens: typeof meta.candidatesTokenCount === "number" ? meta.candidatesTokenCount : 0,
|
|
1391
|
+
total_tokens: typeof meta.totalTokenCount === "number" ? meta.totalTokenCount : 0
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (parsed.usage && typeof parsed.usage === "object") {
|
|
1396
|
+
const u = parsed.usage;
|
|
1397
|
+
return {
|
|
1398
|
+
prompt_tokens: typeof u.prompt_tokens === "number" ? u.prompt_tokens : 0,
|
|
1399
|
+
completion_tokens: typeof u.completion_tokens === "number" ? u.completion_tokens : 0,
|
|
1400
|
+
total_tokens: typeof u.total_tokens === "number" ? u.total_tokens : 0
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
} catch {}
|
|
1404
|
+
}
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
// src/auth/antigravity/tools.ts
|
|
1408
|
+
function normalizeToolsForGemini(tools) {
|
|
1409
|
+
if (!tools || tools.length === 0) {
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
const functionDeclarations = [];
|
|
1413
|
+
for (const tool of tools) {
|
|
1414
|
+
if (!tool || typeof tool !== "object") {
|
|
1415
|
+
continue;
|
|
1416
|
+
}
|
|
1417
|
+
const toolType = tool.type ?? "function";
|
|
1418
|
+
if (toolType === "function" && tool.function) {
|
|
1419
|
+
const declaration = {
|
|
1420
|
+
name: tool.function.name
|
|
1421
|
+
};
|
|
1422
|
+
if (tool.function.description) {
|
|
1423
|
+
declaration.description = tool.function.description;
|
|
1424
|
+
}
|
|
1425
|
+
if (tool.function.parameters) {
|
|
1426
|
+
declaration.parameters = tool.function.parameters;
|
|
1427
|
+
} else {
|
|
1428
|
+
declaration.parameters = { type: "object", properties: {} };
|
|
1429
|
+
}
|
|
1430
|
+
functionDeclarations.push(declaration);
|
|
1431
|
+
} else if (toolType !== "function" && process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
1432
|
+
console.warn(`[antigravity-tools] Unsupported tool type: "${toolType}". Tool will be skipped.`);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
if (functionDeclarations.length === 0) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
return { functionDeclarations };
|
|
1439
|
+
}
|
|
1440
|
+
function normalizeToolResultsFromGemini(results) {
|
|
1441
|
+
if (!results || results.length === 0) {
|
|
1442
|
+
return [];
|
|
1443
|
+
}
|
|
1444
|
+
const toolCalls = [];
|
|
1445
|
+
let callCounter = 0;
|
|
1446
|
+
for (const result of results) {
|
|
1447
|
+
if (result.functionCall) {
|
|
1448
|
+
callCounter++;
|
|
1449
|
+
const toolCall = {
|
|
1450
|
+
id: `call_${Date.now()}_${callCounter}`,
|
|
1451
|
+
type: "function",
|
|
1452
|
+
function: {
|
|
1453
|
+
name: result.functionCall.name,
|
|
1454
|
+
arguments: JSON.stringify(result.functionCall.args ?? {})
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
toolCalls.push(toolCall);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return toolCalls;
|
|
1461
|
+
}
|
|
1462
|
+
function convertFunctionCallToToolCall(functionCall, id) {
|
|
1463
|
+
return {
|
|
1464
|
+
id: id ?? `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
1465
|
+
type: "function",
|
|
1466
|
+
function: {
|
|
1467
|
+
name: functionCall.name,
|
|
1468
|
+
arguments: JSON.stringify(functionCall.args ?? {})
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
function hasFunctionTools(tools) {
|
|
1473
|
+
if (!tools || tools.length === 0) {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
return tools.some((tool) => tool.type === "function" && tool.function);
|
|
1477
|
+
}
|
|
1478
|
+
function extractFunctionDeclarations(tools) {
|
|
1479
|
+
if (!tools || typeof tools !== "object") {
|
|
1480
|
+
return [];
|
|
1481
|
+
}
|
|
1482
|
+
const geminiTools = tools;
|
|
1483
|
+
if (Array.isArray(geminiTools.functionDeclarations) && geminiTools.functionDeclarations.length > 0) {
|
|
1484
|
+
return geminiTools.functionDeclarations;
|
|
1485
|
+
}
|
|
1486
|
+
if (Array.isArray(tools)) {
|
|
1487
|
+
const normalized = normalizeToolsForGemini(tools);
|
|
1488
|
+
return normalized?.functionDeclarations ?? [];
|
|
1489
|
+
}
|
|
1490
|
+
return [];
|
|
1491
|
+
}
|
|
1492
|
+
// src/auth/antigravity/thinking.ts
|
|
1493
|
+
var DEFAULT_THINKING_BUDGET = 16000;
|
|
1494
|
+
function shouldIncludeThinking(model) {
|
|
1495
|
+
if (!model || typeof model !== "string") {
|
|
1496
|
+
return false;
|
|
1497
|
+
}
|
|
1498
|
+
const lowerModel = model.toLowerCase();
|
|
1499
|
+
if (lowerModel.endsWith("-high")) {
|
|
1500
|
+
return true;
|
|
1501
|
+
}
|
|
1502
|
+
if (lowerModel.includes("thinking")) {
|
|
1503
|
+
return true;
|
|
1504
|
+
}
|
|
1505
|
+
return false;
|
|
1506
|
+
}
|
|
1507
|
+
function isThinkingCapableModel(model) {
|
|
1508
|
+
if (!model || typeof model !== "string") {
|
|
1509
|
+
return false;
|
|
1510
|
+
}
|
|
1511
|
+
const lowerModel = model.toLowerCase();
|
|
1512
|
+
return lowerModel.includes("thinking") || lowerModel.includes("gemini-3") || lowerModel.endsWith("-high");
|
|
1513
|
+
}
|
|
1514
|
+
function isThinkingPart(part) {
|
|
1515
|
+
if (part.thought === true) {
|
|
1516
|
+
return true;
|
|
1517
|
+
}
|
|
1518
|
+
if (part.type === "thinking" || part.type === "reasoning") {
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
return false;
|
|
1522
|
+
}
|
|
1523
|
+
function hasValidSignature(part) {
|
|
1524
|
+
if (part.thought === true && part.thoughtSignature) {
|
|
1525
|
+
return true;
|
|
1526
|
+
}
|
|
1527
|
+
if ((part.type === "thinking" || part.type === "reasoning") && part.signature) {
|
|
1528
|
+
return true;
|
|
1529
|
+
}
|
|
1530
|
+
return false;
|
|
1531
|
+
}
|
|
1532
|
+
function extractThinkingBlocks(response) {
|
|
1533
|
+
const thinkingBlocks = [];
|
|
1534
|
+
if (response.candidates && Array.isArray(response.candidates)) {
|
|
1535
|
+
for (const candidate of response.candidates) {
|
|
1536
|
+
const parts = candidate.content?.parts;
|
|
1537
|
+
if (!parts || !Array.isArray(parts)) {
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
for (let i = 0;i < parts.length; i++) {
|
|
1541
|
+
const part = parts[i];
|
|
1542
|
+
if (!part || typeof part !== "object") {
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
if (isThinkingPart(part)) {
|
|
1546
|
+
const block = {
|
|
1547
|
+
text: part.text || "",
|
|
1548
|
+
index: thinkingBlocks.length
|
|
1549
|
+
};
|
|
1550
|
+
if (part.thought === true && part.thoughtSignature) {
|
|
1551
|
+
block.signature = part.thoughtSignature;
|
|
1552
|
+
} else if (part.signature) {
|
|
1553
|
+
block.signature = part.signature;
|
|
1554
|
+
}
|
|
1555
|
+
thinkingBlocks.push(block);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
if (response.content && Array.isArray(response.content)) {
|
|
1561
|
+
for (let i = 0;i < response.content.length; i++) {
|
|
1562
|
+
const item = response.content[i];
|
|
1563
|
+
if (!item || typeof item !== "object") {
|
|
1564
|
+
continue;
|
|
1565
|
+
}
|
|
1566
|
+
if (item.type === "thinking" || item.type === "reasoning") {
|
|
1567
|
+
thinkingBlocks.push({
|
|
1568
|
+
text: item.text || "",
|
|
1569
|
+
signature: item.signature,
|
|
1570
|
+
index: thinkingBlocks.length
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
const combinedThinking = thinkingBlocks.map((b) => b.text).join(`
|
|
1576
|
+
|
|
1577
|
+
`);
|
|
1578
|
+
return {
|
|
1579
|
+
thinkingBlocks,
|
|
1580
|
+
combinedThinking,
|
|
1581
|
+
hasThinking: thinkingBlocks.length > 0
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function formatThinkingForOpenAI(thinking) {
|
|
1585
|
+
if (!thinking || !Array.isArray(thinking) || thinking.length === 0) {
|
|
1586
|
+
return [];
|
|
1587
|
+
}
|
|
1588
|
+
return thinking.map((block) => {
|
|
1589
|
+
const formatted = {
|
|
1590
|
+
type: "reasoning",
|
|
1591
|
+
text: block.text || ""
|
|
1592
|
+
};
|
|
1593
|
+
if (block.signature) {
|
|
1594
|
+
formatted.signature = block.signature;
|
|
1595
|
+
}
|
|
1596
|
+
return formatted;
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
function transformCandidateThinking(candidate) {
|
|
1600
|
+
if (!candidate || typeof candidate !== "object") {
|
|
1601
|
+
return candidate;
|
|
1602
|
+
}
|
|
1603
|
+
const content = candidate.content;
|
|
1604
|
+
if (!content || typeof content !== "object" || !Array.isArray(content.parts)) {
|
|
1605
|
+
return candidate;
|
|
1606
|
+
}
|
|
1607
|
+
const thinkingTexts = [];
|
|
1608
|
+
const transformedParts = content.parts.map((part) => {
|
|
1609
|
+
if (part && typeof part === "object" && part.thought === true) {
|
|
1610
|
+
thinkingTexts.push(part.text || "");
|
|
1611
|
+
return {
|
|
1612
|
+
...part,
|
|
1613
|
+
type: "reasoning",
|
|
1614
|
+
thought: undefined
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
return part;
|
|
1618
|
+
});
|
|
1619
|
+
const result = {
|
|
1620
|
+
...candidate,
|
|
1621
|
+
content: { ...content, parts: transformedParts }
|
|
1622
|
+
};
|
|
1623
|
+
if (thinkingTexts.length > 0) {
|
|
1624
|
+
result.reasoning_content = thinkingTexts.join(`
|
|
1625
|
+
|
|
1626
|
+
`);
|
|
1627
|
+
}
|
|
1628
|
+
return result;
|
|
1629
|
+
}
|
|
1630
|
+
function transformAnthropicThinking(content) {
|
|
1631
|
+
if (!content || !Array.isArray(content)) {
|
|
1632
|
+
return content;
|
|
1633
|
+
}
|
|
1634
|
+
return content.map((block) => {
|
|
1635
|
+
if (block && typeof block === "object" && block.type === "thinking") {
|
|
1636
|
+
return {
|
|
1637
|
+
type: "reasoning",
|
|
1638
|
+
text: block.text || "",
|
|
1639
|
+
...block.signature ? { signature: block.signature } : {}
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
return block;
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
function filterUnsignedThinkingBlocks(parts) {
|
|
1646
|
+
if (!parts || !Array.isArray(parts)) {
|
|
1647
|
+
return parts;
|
|
1648
|
+
}
|
|
1649
|
+
return parts.filter((part) => {
|
|
1650
|
+
if (!part || typeof part !== "object") {
|
|
1651
|
+
return true;
|
|
1652
|
+
}
|
|
1653
|
+
if (isThinkingPart(part)) {
|
|
1654
|
+
return hasValidSignature(part);
|
|
1655
|
+
}
|
|
1656
|
+
return true;
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
function transformResponseThinking(response) {
|
|
1660
|
+
if (!response || typeof response !== "object") {
|
|
1661
|
+
return response;
|
|
1662
|
+
}
|
|
1663
|
+
const result = { ...response };
|
|
1664
|
+
if (Array.isArray(result.candidates)) {
|
|
1665
|
+
result.candidates = result.candidates.map(transformCandidateThinking);
|
|
1666
|
+
}
|
|
1667
|
+
if (Array.isArray(result.content)) {
|
|
1668
|
+
result.content = transformAnthropicThinking(result.content);
|
|
1669
|
+
}
|
|
1670
|
+
return result;
|
|
1671
|
+
}
|
|
1672
|
+
function normalizeThinkingConfig(config) {
|
|
1673
|
+
if (!config || typeof config !== "object") {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
const record = config;
|
|
1677
|
+
const budgetRaw = record.thinkingBudget ?? record.thinking_budget;
|
|
1678
|
+
const includeRaw = record.includeThoughts ?? record.include_thoughts;
|
|
1679
|
+
const thinkingBudget = typeof budgetRaw === "number" && Number.isFinite(budgetRaw) ? budgetRaw : undefined;
|
|
1680
|
+
const includeThoughts = typeof includeRaw === "boolean" ? includeRaw : undefined;
|
|
1681
|
+
const enableThinking = thinkingBudget !== undefined && thinkingBudget > 0;
|
|
1682
|
+
const finalInclude = enableThinking ? includeThoughts ?? false : false;
|
|
1683
|
+
if (!enableThinking && finalInclude === false && thinkingBudget === undefined && includeThoughts === undefined) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
const normalized = {};
|
|
1687
|
+
if (thinkingBudget !== undefined) {
|
|
1688
|
+
normalized.thinkingBudget = thinkingBudget;
|
|
1689
|
+
}
|
|
1690
|
+
if (finalInclude !== undefined) {
|
|
1691
|
+
normalized.includeThoughts = finalInclude;
|
|
1692
|
+
}
|
|
1693
|
+
return normalized;
|
|
1694
|
+
}
|
|
1695
|
+
function extractThinkingConfig(requestPayload, generationConfig, extraBody) {
|
|
1696
|
+
const thinkingConfig = generationConfig?.thinkingConfig ?? extraBody?.thinkingConfig ?? requestPayload.thinkingConfig;
|
|
1697
|
+
if (thinkingConfig && typeof thinkingConfig === "object") {
|
|
1698
|
+
const config = thinkingConfig;
|
|
1699
|
+
return {
|
|
1700
|
+
includeThoughts: Boolean(config.includeThoughts),
|
|
1701
|
+
thinkingBudget: typeof config.thinkingBudget === "number" ? config.thinkingBudget : DEFAULT_THINKING_BUDGET
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
const anthropicThinking = extraBody?.thinking ?? requestPayload.thinking;
|
|
1705
|
+
if (anthropicThinking && typeof anthropicThinking === "object") {
|
|
1706
|
+
const thinking = anthropicThinking;
|
|
1707
|
+
if (thinking.type === "enabled" || thinking.budgetTokens) {
|
|
1708
|
+
return {
|
|
1709
|
+
includeThoughts: true,
|
|
1710
|
+
thinkingBudget: typeof thinking.budgetTokens === "number" ? thinking.budgetTokens : DEFAULT_THINKING_BUDGET
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
const reasoningEffort = requestPayload.reasoning_effort ?? extraBody?.reasoning_effort;
|
|
1715
|
+
if (reasoningEffort && typeof reasoningEffort === "string") {
|
|
1716
|
+
const budget = REASONING_EFFORT_BUDGET_MAP[reasoningEffort];
|
|
1717
|
+
if (budget !== undefined) {
|
|
1718
|
+
if (reasoningEffort === "none") {
|
|
1719
|
+
return { deleteThinkingConfig: true };
|
|
1720
|
+
}
|
|
1721
|
+
return {
|
|
1722
|
+
includeThoughts: true,
|
|
1723
|
+
thinkingBudget: budget
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
function resolveThinkingConfig(userConfig, isThinkingModel, isClaudeModel, hasAssistantHistory) {
|
|
1730
|
+
if (isClaudeModel && hasAssistantHistory) {
|
|
1731
|
+
return { includeThoughts: false, thinkingBudget: 0 };
|
|
1732
|
+
}
|
|
1733
|
+
if (isThinkingModel && !userConfig) {
|
|
1734
|
+
return { includeThoughts: true, thinkingBudget: DEFAULT_THINKING_BUDGET };
|
|
1735
|
+
}
|
|
1736
|
+
return userConfig;
|
|
1737
|
+
}
|
|
1738
|
+
function getModelThinkingConfig(model) {
|
|
1739
|
+
const normalized = normalizeModelId(model);
|
|
1740
|
+
if (ANTIGRAVITY_MODEL_CONFIGS[normalized]) {
|
|
1741
|
+
return ANTIGRAVITY_MODEL_CONFIGS[normalized];
|
|
1742
|
+
}
|
|
1743
|
+
if (normalized.includes("gemini-3")) {
|
|
1744
|
+
return {
|
|
1745
|
+
thinkingType: "levels",
|
|
1746
|
+
min: 128,
|
|
1747
|
+
max: 32768,
|
|
1748
|
+
zeroAllowed: false,
|
|
1749
|
+
levels: ["low", "high"]
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
if (normalized.includes("gemini-2.5")) {
|
|
1753
|
+
return {
|
|
1754
|
+
thinkingType: "numeric",
|
|
1755
|
+
min: 0,
|
|
1756
|
+
max: 24576,
|
|
1757
|
+
zeroAllowed: true
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
if (normalized.includes("claude")) {
|
|
1761
|
+
return {
|
|
1762
|
+
thinkingType: "numeric",
|
|
1763
|
+
min: 1024,
|
|
1764
|
+
max: 200000,
|
|
1765
|
+
zeroAllowed: false
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
function budgetToLevel(budget, model) {
|
|
1771
|
+
const config = getModelThinkingConfig(model);
|
|
1772
|
+
if (!config?.levels) {
|
|
1773
|
+
return "medium";
|
|
1774
|
+
}
|
|
1775
|
+
const budgetMap = {
|
|
1776
|
+
512: "minimal",
|
|
1777
|
+
1024: "low",
|
|
1778
|
+
8192: "medium",
|
|
1779
|
+
24576: "high"
|
|
1780
|
+
};
|
|
1781
|
+
if (budgetMap[budget]) {
|
|
1782
|
+
return budgetMap[budget];
|
|
1783
|
+
}
|
|
1784
|
+
return config.levels[config.levels.length - 1] || "high";
|
|
1785
|
+
}
|
|
1786
|
+
function applyThinkingConfigToRequest(requestBody, model, config) {
|
|
1787
|
+
if ("deleteThinkingConfig" in config && config.deleteThinkingConfig) {
|
|
1788
|
+
if (requestBody.request && typeof requestBody.request === "object") {
|
|
1789
|
+
const req2 = requestBody.request;
|
|
1790
|
+
if (req2.generationConfig && typeof req2.generationConfig === "object") {
|
|
1791
|
+
const genConfig2 = req2.generationConfig;
|
|
1792
|
+
delete genConfig2.thinkingConfig;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
const modelConfig = getModelThinkingConfig(model);
|
|
1798
|
+
if (!modelConfig) {
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
if (!requestBody.request || typeof requestBody.request !== "object") {
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
const req = requestBody.request;
|
|
1805
|
+
if (!req.generationConfig || typeof req.generationConfig !== "object") {
|
|
1806
|
+
req.generationConfig = {};
|
|
1807
|
+
}
|
|
1808
|
+
const genConfig = req.generationConfig;
|
|
1809
|
+
genConfig.thinkingConfig = {};
|
|
1810
|
+
const thinkingConfig = genConfig.thinkingConfig;
|
|
1811
|
+
thinkingConfig.include_thoughts = true;
|
|
1812
|
+
if (modelConfig.thinkingType === "numeric") {
|
|
1813
|
+
thinkingConfig.thinkingBudget = config.thinkingBudget;
|
|
1814
|
+
} else if (modelConfig.thinkingType === "levels") {
|
|
1815
|
+
const budget = config.thinkingBudget ?? DEFAULT_THINKING_BUDGET;
|
|
1816
|
+
let level = budgetToLevel(budget, model);
|
|
1817
|
+
level = level.toLowerCase();
|
|
1818
|
+
thinkingConfig.thinkingLevel = level;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
// src/auth/antigravity/thought-signature-store.ts
|
|
1822
|
+
var signatureStore = new Map;
|
|
1823
|
+
var sessionIdStore = new Map;
|
|
1824
|
+
function setThoughtSignature(sessionKey, signature) {
|
|
1825
|
+
if (sessionKey && signature) {
|
|
1826
|
+
signatureStore.set(sessionKey, signature);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
function getThoughtSignature(sessionKey) {
|
|
1830
|
+
return signatureStore.get(sessionKey);
|
|
1831
|
+
}
|
|
1832
|
+
function clearThoughtSignature(sessionKey) {
|
|
1833
|
+
signatureStore.delete(sessionKey);
|
|
1834
|
+
}
|
|
1835
|
+
function getOrCreateSessionId(fetchInstanceId, sessionId) {
|
|
1836
|
+
if (sessionId) {
|
|
1837
|
+
sessionIdStore.set(fetchInstanceId, sessionId);
|
|
1838
|
+
return sessionId;
|
|
1839
|
+
}
|
|
1840
|
+
const existing = sessionIdStore.get(fetchInstanceId);
|
|
1841
|
+
if (existing) {
|
|
1842
|
+
return existing;
|
|
1843
|
+
}
|
|
1844
|
+
const n = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
|
1845
|
+
const newSessionId = `-${n}`;
|
|
1846
|
+
sessionIdStore.set(fetchInstanceId, newSessionId);
|
|
1847
|
+
return newSessionId;
|
|
1848
|
+
}
|
|
1849
|
+
function clearSessionId(fetchInstanceId) {
|
|
1850
|
+
sessionIdStore.delete(fetchInstanceId);
|
|
1851
|
+
}
|
|
1852
|
+
function clearFetchInstanceData(fetchInstanceId) {
|
|
1853
|
+
signatureStore.delete(fetchInstanceId);
|
|
1854
|
+
sessionIdStore.delete(fetchInstanceId);
|
|
1855
|
+
}
|
|
1856
|
+
// src/auth/antigravity/message-converter.ts
|
|
1857
|
+
function debugLog3(message) {
|
|
1858
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
1859
|
+
console.log(`[antigravity-converter] ${message}`);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
function convertOpenAIToGemini(messages, thoughtSignature) {
|
|
1863
|
+
debugLog3(`Converting ${messages.length} messages, signature: ${thoughtSignature ? "present" : "none"}`);
|
|
1864
|
+
const contents = [];
|
|
1865
|
+
for (const msg of messages) {
|
|
1866
|
+
if (msg.role === "system") {
|
|
1867
|
+
contents.push({
|
|
1868
|
+
role: "user",
|
|
1869
|
+
parts: [{ text: typeof msg.content === "string" ? msg.content : "" }]
|
|
1870
|
+
});
|
|
1871
|
+
continue;
|
|
1872
|
+
}
|
|
1873
|
+
if (msg.role === "user") {
|
|
1874
|
+
const parts = convertContentToParts(msg.content);
|
|
1875
|
+
contents.push({ role: "user", parts });
|
|
1876
|
+
continue;
|
|
1877
|
+
}
|
|
1878
|
+
if (msg.role === "assistant") {
|
|
1879
|
+
const parts = [];
|
|
1880
|
+
if (msg.content) {
|
|
1881
|
+
parts.push(...convertContentToParts(msg.content));
|
|
1882
|
+
}
|
|
1883
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
1884
|
+
for (const toolCall of msg.tool_calls) {
|
|
1885
|
+
let args = {};
|
|
1886
|
+
try {
|
|
1887
|
+
args = JSON.parse(toolCall.function.arguments);
|
|
1888
|
+
} catch {
|
|
1889
|
+
args = {};
|
|
1890
|
+
}
|
|
1891
|
+
const part = {
|
|
1892
|
+
functionCall: {
|
|
1893
|
+
name: toolCall.function.name,
|
|
1894
|
+
args
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
part.thoughtSignature = thoughtSignature || SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
1898
|
+
debugLog3(`Injected signature into functionCall: ${toolCall.function.name} (${thoughtSignature ? "provided" : "default"})`);
|
|
1899
|
+
parts.push(part);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
if (parts.length > 0) {
|
|
1903
|
+
contents.push({ role: "model", parts });
|
|
1904
|
+
}
|
|
1905
|
+
continue;
|
|
1906
|
+
}
|
|
1907
|
+
if (msg.role === "tool") {
|
|
1908
|
+
let response = {};
|
|
1909
|
+
try {
|
|
1910
|
+
response = typeof msg.content === "string" ? JSON.parse(msg.content) : { result: msg.content };
|
|
1911
|
+
} catch {
|
|
1912
|
+
response = { result: msg.content };
|
|
1913
|
+
}
|
|
1914
|
+
const toolName = msg.name || "unknown";
|
|
1915
|
+
contents.push({
|
|
1916
|
+
role: "user",
|
|
1917
|
+
parts: [{
|
|
1918
|
+
functionResponse: {
|
|
1919
|
+
name: toolName,
|
|
1920
|
+
response
|
|
1921
|
+
}
|
|
1922
|
+
}]
|
|
1923
|
+
});
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
debugLog3(`Converted to ${contents.length} content blocks`);
|
|
1928
|
+
return contents;
|
|
1929
|
+
}
|
|
1930
|
+
function convertContentToParts(content) {
|
|
1931
|
+
if (!content) {
|
|
1932
|
+
return [{ text: "" }];
|
|
1933
|
+
}
|
|
1934
|
+
if (typeof content === "string") {
|
|
1935
|
+
return [{ text: content }];
|
|
1936
|
+
}
|
|
1937
|
+
const parts = [];
|
|
1938
|
+
for (const part of content) {
|
|
1939
|
+
if (part.type === "text" && part.text) {
|
|
1940
|
+
parts.push({ text: part.text });
|
|
1941
|
+
} else if (part.type === "image_url" && part.image_url?.url) {
|
|
1942
|
+
const url = part.image_url.url;
|
|
1943
|
+
if (url.startsWith("data:")) {
|
|
1944
|
+
const match = url.match(/^data:([^;]+);base64,(.+)$/);
|
|
1945
|
+
if (match) {
|
|
1946
|
+
parts.push({
|
|
1947
|
+
inlineData: {
|
|
1948
|
+
mimeType: match[1],
|
|
1949
|
+
data: match[2]
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return parts.length > 0 ? parts : [{ text: "" }];
|
|
1957
|
+
}
|
|
1958
|
+
function hasOpenAIMessages(body) {
|
|
1959
|
+
return Array.isArray(body.messages) && body.messages.length > 0;
|
|
1960
|
+
}
|
|
1961
|
+
function convertRequestBody(body, thoughtSignature) {
|
|
1962
|
+
if (!hasOpenAIMessages(body)) {
|
|
1963
|
+
debugLog3("No messages array found, returning body as-is");
|
|
1964
|
+
return body;
|
|
1965
|
+
}
|
|
1966
|
+
const messages = body.messages;
|
|
1967
|
+
const contents = convertOpenAIToGemini(messages, thoughtSignature);
|
|
1968
|
+
const converted = { ...body };
|
|
1969
|
+
delete converted.messages;
|
|
1970
|
+
converted.contents = contents;
|
|
1971
|
+
debugLog3(`Converted body: messages → contents (${contents.length} blocks)`);
|
|
1972
|
+
return converted;
|
|
1973
|
+
}
|
|
1974
|
+
// src/auth/antigravity/storage.ts
|
|
1975
|
+
import { promises as fs } from "node:fs";
|
|
1976
|
+
import { join, dirname } from "node:path";
|
|
1977
|
+
|
|
1978
|
+
// src/shared/data-path.ts
|
|
1979
|
+
import path from "node:path";
|
|
1980
|
+
import os from "node:os";
|
|
1981
|
+
function getDataDir() {
|
|
1982
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
|
|
1983
|
+
return path.join(xdgConfig, "kraken-code");
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
// src/auth/antigravity/storage.ts
|
|
1987
|
+
function getPluginDataDir() {
|
|
1988
|
+
return join(getDataDir(), "opencode");
|
|
1989
|
+
}
|
|
1990
|
+
function getStoragePath() {
|
|
1991
|
+
return join(getPluginDataDir(), "kraken-code-accounts.json");
|
|
1992
|
+
}
|
|
1993
|
+
async function loadAccounts(path2) {
|
|
1994
|
+
const storagePath = path2 ?? getStoragePath();
|
|
1995
|
+
try {
|
|
1996
|
+
const content = await fs.readFile(storagePath, "utf-8");
|
|
1997
|
+
const data = JSON.parse(content);
|
|
1998
|
+
if (!isValidAccountStorage(data)) {
|
|
1999
|
+
return null;
|
|
2000
|
+
}
|
|
2001
|
+
return data;
|
|
2002
|
+
} catch (error) {
|
|
2003
|
+
const errorCode = error.code;
|
|
2004
|
+
if (errorCode === "ENOENT") {
|
|
2005
|
+
return null;
|
|
2006
|
+
}
|
|
2007
|
+
if (error instanceof SyntaxError) {
|
|
2008
|
+
return null;
|
|
2009
|
+
}
|
|
2010
|
+
throw error;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
async function saveAccounts(storage, path2) {
|
|
2014
|
+
const storagePath = path2 ?? getStoragePath();
|
|
2015
|
+
await fs.mkdir(dirname(storagePath), { recursive: true });
|
|
2016
|
+
const content = JSON.stringify(storage, null, 2);
|
|
2017
|
+
const tempPath = `${storagePath}.tmp.${process.pid}.${Date.now()}`;
|
|
2018
|
+
await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
|
|
2019
|
+
try {
|
|
2020
|
+
await fs.rename(tempPath, storagePath);
|
|
2021
|
+
} catch (error) {
|
|
2022
|
+
await fs.unlink(tempPath).catch(() => {});
|
|
2023
|
+
throw error;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
function isValidAccountStorage(data) {
|
|
2027
|
+
if (typeof data !== "object" || data === null) {
|
|
2028
|
+
return false;
|
|
2029
|
+
}
|
|
2030
|
+
const obj = data;
|
|
2031
|
+
if (typeof obj.version !== "number") {
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
if (!Array.isArray(obj.accounts)) {
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
if (typeof obj.activeIndex !== "number") {
|
|
2038
|
+
return false;
|
|
2039
|
+
}
|
|
2040
|
+
return true;
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// src/auth/antigravity/accounts.ts
|
|
2044
|
+
function isRateLimitedForFamily(account, family) {
|
|
2045
|
+
const resetTime = account.rateLimits[family];
|
|
2046
|
+
return resetTime !== undefined && Date.now() < resetTime;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
class AccountManager {
|
|
2050
|
+
accounts = [];
|
|
2051
|
+
currentIndex = 0;
|
|
2052
|
+
activeIndex = 0;
|
|
2053
|
+
constructor(auth, storedAccounts) {
|
|
2054
|
+
if (storedAccounts && storedAccounts.accounts.length > 0) {
|
|
2055
|
+
const validActiveIndex = typeof storedAccounts.activeIndex === "number" && storedAccounts.activeIndex >= 0 && storedAccounts.activeIndex < storedAccounts.accounts.length ? storedAccounts.activeIndex : 0;
|
|
2056
|
+
this.activeIndex = validActiveIndex;
|
|
2057
|
+
this.currentIndex = validActiveIndex;
|
|
2058
|
+
this.accounts = storedAccounts.accounts.map((acc, index) => ({
|
|
2059
|
+
index,
|
|
2060
|
+
parts: {
|
|
2061
|
+
refreshToken: acc.refreshToken,
|
|
2062
|
+
projectId: acc.projectId,
|
|
2063
|
+
managedProjectId: acc.managedProjectId
|
|
2064
|
+
},
|
|
2065
|
+
access: index === validActiveIndex ? auth.access : acc.accessToken,
|
|
2066
|
+
expires: index === validActiveIndex ? auth.expires : acc.expiresAt,
|
|
2067
|
+
rateLimits: acc.rateLimits ?? {},
|
|
2068
|
+
lastUsed: 0,
|
|
2069
|
+
email: acc.email,
|
|
2070
|
+
tier: acc.tier
|
|
2071
|
+
}));
|
|
2072
|
+
} else {
|
|
2073
|
+
this.activeIndex = 0;
|
|
2074
|
+
this.currentIndex = 0;
|
|
2075
|
+
const parts = parseStoredToken(auth.refresh);
|
|
2076
|
+
this.accounts.push({
|
|
2077
|
+
index: 0,
|
|
2078
|
+
parts,
|
|
2079
|
+
access: auth.access,
|
|
2080
|
+
expires: auth.expires,
|
|
2081
|
+
rateLimits: {},
|
|
2082
|
+
lastUsed: 0
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
getAccountCount() {
|
|
2087
|
+
return this.accounts.length;
|
|
2088
|
+
}
|
|
2089
|
+
getCurrentAccount() {
|
|
2090
|
+
if (this.activeIndex >= 0 && this.activeIndex < this.accounts.length) {
|
|
2091
|
+
return this.accounts[this.activeIndex] ?? null;
|
|
2092
|
+
}
|
|
2093
|
+
return null;
|
|
2094
|
+
}
|
|
2095
|
+
getAccounts() {
|
|
2096
|
+
return this.accounts.map((acc) => ({ ...acc }));
|
|
2097
|
+
}
|
|
2098
|
+
getCurrentOrNextForFamily(family) {
|
|
2099
|
+
for (const account of this.accounts) {
|
|
2100
|
+
this.clearExpiredRateLimits(account);
|
|
2101
|
+
}
|
|
2102
|
+
const current = this.getCurrentAccount();
|
|
2103
|
+
if (current) {
|
|
2104
|
+
if (!isRateLimitedForFamily(current, family)) {
|
|
2105
|
+
const betterTierAvailable = current.tier !== "paid" && this.accounts.some((a) => a.tier === "paid" && !isRateLimitedForFamily(a, family));
|
|
2106
|
+
if (!betterTierAvailable) {
|
|
2107
|
+
current.lastUsed = Date.now();
|
|
2108
|
+
return current;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
const next = this.getNextForFamily(family);
|
|
2113
|
+
if (next) {
|
|
2114
|
+
this.activeIndex = next.index;
|
|
2115
|
+
}
|
|
2116
|
+
return next;
|
|
2117
|
+
}
|
|
2118
|
+
getNextForFamily(family) {
|
|
2119
|
+
const available = this.accounts.filter((a) => !isRateLimitedForFamily(a, family));
|
|
2120
|
+
if (available.length === 0) {
|
|
2121
|
+
return null;
|
|
2122
|
+
}
|
|
2123
|
+
const paidAvailable = available.filter((a) => a.tier === "paid");
|
|
2124
|
+
const pool = paidAvailable.length > 0 ? paidAvailable : available;
|
|
2125
|
+
const account = pool[this.currentIndex % pool.length];
|
|
2126
|
+
if (!account) {
|
|
2127
|
+
return null;
|
|
2128
|
+
}
|
|
2129
|
+
this.currentIndex++;
|
|
2130
|
+
account.lastUsed = Date.now();
|
|
2131
|
+
return account;
|
|
2132
|
+
}
|
|
2133
|
+
markRateLimited(account, retryAfterMs, family) {
|
|
2134
|
+
account.rateLimits[family] = Date.now() + retryAfterMs;
|
|
2135
|
+
}
|
|
2136
|
+
clearExpiredRateLimits(account) {
|
|
2137
|
+
const now = Date.now();
|
|
2138
|
+
for (const family of MODEL_FAMILIES) {
|
|
2139
|
+
if (account.rateLimits[family] !== undefined && now >= account.rateLimits[family]) {
|
|
2140
|
+
delete account.rateLimits[family];
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
addAccount(parts, access, expires, email, tier) {
|
|
2145
|
+
this.accounts.push({
|
|
2146
|
+
index: this.accounts.length,
|
|
2147
|
+
parts,
|
|
2148
|
+
access,
|
|
2149
|
+
expires,
|
|
2150
|
+
rateLimits: {},
|
|
2151
|
+
lastUsed: 0,
|
|
2152
|
+
email,
|
|
2153
|
+
tier
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
removeAccount(index) {
|
|
2157
|
+
if (index < 0 || index >= this.accounts.length) {
|
|
2158
|
+
return false;
|
|
2159
|
+
}
|
|
2160
|
+
this.accounts.splice(index, 1);
|
|
2161
|
+
if (index < this.activeIndex) {
|
|
2162
|
+
this.activeIndex--;
|
|
2163
|
+
} else if (index === this.activeIndex) {
|
|
2164
|
+
this.activeIndex = Math.min(this.activeIndex, Math.max(0, this.accounts.length - 1));
|
|
2165
|
+
}
|
|
2166
|
+
if (index < this.currentIndex) {
|
|
2167
|
+
this.currentIndex--;
|
|
2168
|
+
} else if (index === this.currentIndex) {
|
|
2169
|
+
this.currentIndex = Math.min(this.currentIndex, Math.max(0, this.accounts.length - 1));
|
|
2170
|
+
}
|
|
2171
|
+
for (let i = 0;i < this.accounts.length; i++) {
|
|
2172
|
+
this.accounts[i].index = i;
|
|
2173
|
+
}
|
|
2174
|
+
return true;
|
|
2175
|
+
}
|
|
2176
|
+
async save(path2) {
|
|
2177
|
+
const storage = {
|
|
2178
|
+
version: 1,
|
|
2179
|
+
accounts: this.accounts.map((acc) => ({
|
|
2180
|
+
email: acc.email ?? "",
|
|
2181
|
+
tier: acc.tier ?? "free",
|
|
2182
|
+
refreshToken: acc.parts.refreshToken,
|
|
2183
|
+
projectId: acc.parts.projectId ?? "",
|
|
2184
|
+
managedProjectId: acc.parts.managedProjectId,
|
|
2185
|
+
accessToken: acc.access ?? "",
|
|
2186
|
+
expiresAt: acc.expires ?? 0,
|
|
2187
|
+
rateLimits: acc.rateLimits
|
|
2188
|
+
})),
|
|
2189
|
+
activeIndex: Math.max(0, this.activeIndex)
|
|
2190
|
+
};
|
|
2191
|
+
await saveAccounts(storage, path2);
|
|
2192
|
+
}
|
|
2193
|
+
toAuthDetails() {
|
|
2194
|
+
const current = this.getCurrentAccount() ?? this.accounts[0];
|
|
2195
|
+
if (!current) {
|
|
2196
|
+
throw new Error("No accounts available");
|
|
2197
|
+
}
|
|
2198
|
+
const allRefreshTokens = this.accounts.map((acc) => formatTokenForStorage(acc.parts.refreshToken, acc.parts.projectId ?? "", acc.parts.managedProjectId)).join("|||");
|
|
2199
|
+
return {
|
|
2200
|
+
type: "oauth",
|
|
2201
|
+
refresh: allRefreshTokens,
|
|
2202
|
+
access: current.access ?? "",
|
|
2203
|
+
expires: current.expires ?? 0
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
// src/auth/antigravity/fetch.ts
|
|
2209
|
+
function debugLog4(message) {
|
|
2210
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
2211
|
+
console.log(`[antigravity-fetch] ${message}`);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
function isRetryableError2(status) {
|
|
2215
|
+
if (status === 0)
|
|
2216
|
+
return true;
|
|
2217
|
+
if (status === 429)
|
|
2218
|
+
return true;
|
|
2219
|
+
if (status >= 500 && status < 600)
|
|
2220
|
+
return true;
|
|
2221
|
+
return false;
|
|
2222
|
+
}
|
|
2223
|
+
function getModelFamilyFromModelName(modelName) {
|
|
2224
|
+
const lower = modelName.toLowerCase();
|
|
2225
|
+
if (lower.includes("claude") || lower.includes("anthropic"))
|
|
2226
|
+
return "claude";
|
|
2227
|
+
if (lower.includes("flash"))
|
|
2228
|
+
return "gemini-flash";
|
|
2229
|
+
if (lower.includes("gemini"))
|
|
2230
|
+
return "gemini-pro";
|
|
2231
|
+
return null;
|
|
2232
|
+
}
|
|
2233
|
+
function getModelFamilyFromUrl(url) {
|
|
2234
|
+
if (url.includes("claude"))
|
|
2235
|
+
return "claude";
|
|
2236
|
+
if (url.includes("flash"))
|
|
2237
|
+
return "gemini-flash";
|
|
2238
|
+
return "gemini-pro";
|
|
2239
|
+
}
|
|
2240
|
+
function getModelFamily(url, init) {
|
|
2241
|
+
if (init?.body && typeof init.body === "string") {
|
|
2242
|
+
try {
|
|
2243
|
+
const body = JSON.parse(init.body);
|
|
2244
|
+
if (typeof body.model === "string") {
|
|
2245
|
+
const fromModel = getModelFamilyFromModelName(body.model);
|
|
2246
|
+
if (fromModel)
|
|
2247
|
+
return fromModel;
|
|
2248
|
+
}
|
|
2249
|
+
} catch {}
|
|
2250
|
+
}
|
|
2251
|
+
return getModelFamilyFromUrl(url);
|
|
2252
|
+
}
|
|
2253
|
+
var GCP_PERMISSION_ERROR_PATTERNS = [
|
|
2254
|
+
"PERMISSION_DENIED",
|
|
2255
|
+
"does not have permission",
|
|
2256
|
+
"Cloud AI Companion API has not been used",
|
|
2257
|
+
"has not been enabled"
|
|
2258
|
+
];
|
|
2259
|
+
function isGcpPermissionError(text) {
|
|
2260
|
+
return GCP_PERMISSION_ERROR_PATTERNS.some((pattern) => text.includes(pattern));
|
|
2261
|
+
}
|
|
2262
|
+
function calculateRetryDelay2(attempt) {
|
|
2263
|
+
return Math.min(200 * Math.pow(2, attempt), 2000);
|
|
2264
|
+
}
|
|
2265
|
+
async function isRetryableResponse(response) {
|
|
2266
|
+
if (isRetryableError2(response.status))
|
|
2267
|
+
return true;
|
|
2268
|
+
if (response.status === 403) {
|
|
2269
|
+
try {
|
|
2270
|
+
const text = await response.clone().text();
|
|
2271
|
+
if (text.includes("SUBSCRIPTION_REQUIRED") || text.includes("Gemini Code Assist license")) {
|
|
2272
|
+
debugLog4(`[RETRY] 403 SUBSCRIPTION_REQUIRED detected, will retry with next endpoint`);
|
|
2273
|
+
return true;
|
|
2274
|
+
}
|
|
2275
|
+
} catch {}
|
|
2276
|
+
}
|
|
2277
|
+
return false;
|
|
2278
|
+
}
|
|
2279
|
+
async function attemptFetch(options) {
|
|
2280
|
+
const { endpoint, url, init, accessToken, projectId, sessionId, modelName, thoughtSignature } = options;
|
|
2281
|
+
debugLog4(`Trying endpoint: ${endpoint}`);
|
|
2282
|
+
try {
|
|
2283
|
+
const rawBody = init.body;
|
|
2284
|
+
if (rawBody !== undefined && typeof rawBody !== "string") {
|
|
2285
|
+
debugLog4(`Non-string body detected (${typeof rawBody}), signaling pass-through`);
|
|
2286
|
+
return "pass-through";
|
|
2287
|
+
}
|
|
2288
|
+
let parsedBody = {};
|
|
2289
|
+
if (rawBody) {
|
|
2290
|
+
try {
|
|
2291
|
+
parsedBody = JSON.parse(rawBody);
|
|
2292
|
+
} catch {
|
|
2293
|
+
parsedBody = {};
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
debugLog4(`[BODY] Keys: ${Object.keys(parsedBody).join(", ")}`);
|
|
2297
|
+
debugLog4(`[BODY] Has contents: ${!!parsedBody.contents}, Has messages: ${!!parsedBody.messages}`);
|
|
2298
|
+
if (parsedBody.contents) {
|
|
2299
|
+
const contents = parsedBody.contents;
|
|
2300
|
+
debugLog4(`[BODY] contents length: ${contents.length}`);
|
|
2301
|
+
contents.forEach((c, i) => {
|
|
2302
|
+
debugLog4(`[BODY] contents[${i}].role: ${c.role}, parts: ${JSON.stringify(c.parts).substring(0, 200)}`);
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
if (parsedBody.tools && Array.isArray(parsedBody.tools)) {
|
|
2306
|
+
const normalizedTools = normalizeToolsForGemini(parsedBody.tools);
|
|
2307
|
+
if (normalizedTools) {
|
|
2308
|
+
parsedBody.tools = normalizedTools;
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
if (hasOpenAIMessages(parsedBody)) {
|
|
2312
|
+
debugLog4(`[CONVERT] Converting OpenAI messages to Gemini contents`);
|
|
2313
|
+
parsedBody = convertRequestBody(parsedBody, thoughtSignature);
|
|
2314
|
+
debugLog4(`[CONVERT] After conversion - Has contents: ${!!parsedBody.contents}`);
|
|
2315
|
+
}
|
|
2316
|
+
const transformed = transformRequest({
|
|
2317
|
+
url,
|
|
2318
|
+
body: parsedBody,
|
|
2319
|
+
accessToken,
|
|
2320
|
+
projectId,
|
|
2321
|
+
sessionId,
|
|
2322
|
+
modelName,
|
|
2323
|
+
endpointOverride: endpoint,
|
|
2324
|
+
thoughtSignature
|
|
2325
|
+
});
|
|
2326
|
+
const effectiveModel = modelName || transformed.body.model;
|
|
2327
|
+
const thinkingConfig = extractThinkingConfig(parsedBody, parsedBody.generationConfig, parsedBody);
|
|
2328
|
+
if (thinkingConfig) {
|
|
2329
|
+
debugLog4(`[THINKING] Applying thinking config for model: ${effectiveModel}`);
|
|
2330
|
+
applyThinkingConfigToRequest(transformed.body, effectiveModel, thinkingConfig);
|
|
2331
|
+
debugLog4(`[THINKING] Thinking config applied successfully`);
|
|
2332
|
+
}
|
|
2333
|
+
debugLog4(`[REQ] streaming=${transformed.streaming}, url=${transformed.url}`);
|
|
2334
|
+
const maxPermissionRetries = 10;
|
|
2335
|
+
for (let attempt = 0;attempt <= maxPermissionRetries; attempt++) {
|
|
2336
|
+
const response = await fetch(transformed.url, {
|
|
2337
|
+
method: init.method || "POST",
|
|
2338
|
+
headers: transformed.headers,
|
|
2339
|
+
body: JSON.stringify(transformed.body),
|
|
2340
|
+
signal: init.signal
|
|
2341
|
+
});
|
|
2342
|
+
debugLog4(`[RESP] status=${response.status} content-type=${response.headers.get("content-type") ?? ""} url=${response.url}`);
|
|
2343
|
+
if (response.status === 401) {
|
|
2344
|
+
debugLog4(`[401] Unauthorized response detected, signaling token refresh needed`);
|
|
2345
|
+
return "needs-refresh";
|
|
2346
|
+
}
|
|
2347
|
+
if (response.status === 403) {
|
|
2348
|
+
try {
|
|
2349
|
+
const text = await response.clone().text();
|
|
2350
|
+
if (isGcpPermissionError(text)) {
|
|
2351
|
+
if (attempt < maxPermissionRetries) {
|
|
2352
|
+
const delay = calculateRetryDelay2(attempt);
|
|
2353
|
+
debugLog4(`[RETRY] GCP permission error, retry ${attempt + 1}/${maxPermissionRetries} after ${delay}ms`);
|
|
2354
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2355
|
+
continue;
|
|
2356
|
+
}
|
|
2357
|
+
debugLog4(`[RETRY] GCP permission error, max retries exceeded`);
|
|
2358
|
+
}
|
|
2359
|
+
} catch {}
|
|
2360
|
+
}
|
|
2361
|
+
if (response.status === 429) {
|
|
2362
|
+
const retryAfter = response.headers.get("retry-after");
|
|
2363
|
+
let retryAfterMs = 60000;
|
|
2364
|
+
if (retryAfter) {
|
|
2365
|
+
const parsed = parseInt(retryAfter, 10);
|
|
2366
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
2367
|
+
retryAfterMs = parsed * 1000;
|
|
2368
|
+
} else {
|
|
2369
|
+
const httpDate = Date.parse(retryAfter);
|
|
2370
|
+
if (!isNaN(httpDate)) {
|
|
2371
|
+
retryAfterMs = Math.max(0, httpDate - Date.now());
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
debugLog4(`[429] Rate limited, retry-after: ${retryAfterMs}ms`);
|
|
2376
|
+
await response.body?.cancel();
|
|
2377
|
+
return { type: "rate-limited", retryAfterMs, status: 429 };
|
|
2378
|
+
}
|
|
2379
|
+
if (response.status >= 500 && response.status < 600) {
|
|
2380
|
+
debugLog4(`[5xx] Server error ${response.status}, marking for rotation`);
|
|
2381
|
+
await response.body?.cancel();
|
|
2382
|
+
return { type: "rate-limited", retryAfterMs: 300000, status: response.status };
|
|
2383
|
+
}
|
|
2384
|
+
if (!response.ok && await isRetryableResponse(response)) {
|
|
2385
|
+
debugLog4(`Endpoint failed: ${endpoint} (status: ${response.status}), trying next`);
|
|
2386
|
+
return null;
|
|
2387
|
+
}
|
|
2388
|
+
return response;
|
|
2389
|
+
}
|
|
2390
|
+
return null;
|
|
2391
|
+
} catch (error) {
|
|
2392
|
+
debugLog4(`Endpoint failed: ${endpoint} (${error instanceof Error ? error.message : "Unknown error"}), trying next`);
|
|
2393
|
+
return null;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
function extractSignatureFromResponse(parsed) {
|
|
2397
|
+
if (!parsed.candidates || !Array.isArray(parsed.candidates)) {
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
for (const candidate of parsed.candidates) {
|
|
2401
|
+
const parts = candidate.content?.parts;
|
|
2402
|
+
if (!parts || !Array.isArray(parts)) {
|
|
2403
|
+
continue;
|
|
2404
|
+
}
|
|
2405
|
+
for (const part of parts) {
|
|
2406
|
+
const sig = part.thoughtSignature || part.thought_signature;
|
|
2407
|
+
if (sig && typeof sig === "string") {
|
|
2408
|
+
return sig;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
async function transformResponseWithThinking(response, modelName, fetchInstanceId) {
|
|
2415
|
+
const streaming = isStreamingResponse(response);
|
|
2416
|
+
let result;
|
|
2417
|
+
if (streaming) {
|
|
2418
|
+
result = await transformStreamingResponse(response);
|
|
2419
|
+
} else {
|
|
2420
|
+
result = await transformResponse(response);
|
|
2421
|
+
}
|
|
2422
|
+
if (streaming) {
|
|
2423
|
+
return result.response;
|
|
2424
|
+
}
|
|
2425
|
+
try {
|
|
2426
|
+
const text = await result.response.clone().text();
|
|
2427
|
+
debugLog4(`[TSIG][RESP] Response text length: ${text.length}`);
|
|
2428
|
+
const parsed = JSON.parse(text);
|
|
2429
|
+
debugLog4(`[TSIG][RESP] Parsed keys: ${Object.keys(parsed).join(", ")}`);
|
|
2430
|
+
debugLog4(`[TSIG][RESP] Has candidates: ${!!parsed.candidates}, count: ${parsed.candidates?.length ?? 0}`);
|
|
2431
|
+
const signature = extractSignatureFromResponse(parsed);
|
|
2432
|
+
debugLog4(`[TSIG][RESP] Signature extracted: ${signature ? signature.substring(0, 30) + "..." : "NONE"}`);
|
|
2433
|
+
if (signature) {
|
|
2434
|
+
setThoughtSignature(fetchInstanceId, signature);
|
|
2435
|
+
debugLog4(`[TSIG][STORE] Stored signature for ${fetchInstanceId}`);
|
|
2436
|
+
} else {
|
|
2437
|
+
debugLog4(`[TSIG][WARN] No signature found in response!`);
|
|
2438
|
+
}
|
|
2439
|
+
if (shouldIncludeThinking(modelName)) {
|
|
2440
|
+
const thinkingResult = extractThinkingBlocks(parsed);
|
|
2441
|
+
if (thinkingResult.hasThinking) {
|
|
2442
|
+
const transformed = transformResponseThinking(parsed);
|
|
2443
|
+
return new Response(JSON.stringify(transformed), {
|
|
2444
|
+
status: result.response.status,
|
|
2445
|
+
statusText: result.response.statusText,
|
|
2446
|
+
headers: result.response.headers
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
} catch {}
|
|
2451
|
+
return result.response;
|
|
2452
|
+
}
|
|
2453
|
+
function createAntigravityFetch(getAuth, client, providerId, clientId, clientSecret, accountManager) {
|
|
2454
|
+
let cachedTokens = null;
|
|
2455
|
+
let cachedProjectId = null;
|
|
2456
|
+
let lastAccountIndex = null;
|
|
2457
|
+
const fetchInstanceId = crypto.randomUUID();
|
|
2458
|
+
let manager = accountManager || null;
|
|
2459
|
+
let accountsLoaded = false;
|
|
2460
|
+
const fetchFn = async (url, init = {}) => {
|
|
2461
|
+
debugLog4(`Intercepting request to: ${url}`);
|
|
2462
|
+
const auth = await getAuth();
|
|
2463
|
+
if (!auth.access || !auth.refresh) {
|
|
2464
|
+
throw new Error("Antigravity: No authentication tokens available");
|
|
2465
|
+
}
|
|
2466
|
+
let refreshParts = parseStoredToken(auth.refresh);
|
|
2467
|
+
if (!accountsLoaded && !manager && auth.refresh) {
|
|
2468
|
+
try {
|
|
2469
|
+
const storedAccounts = await loadAccounts();
|
|
2470
|
+
if (storedAccounts) {
|
|
2471
|
+
manager = new AccountManager({ refresh: auth.refresh, access: auth.access || "", expires: auth.expires || 0 }, storedAccounts);
|
|
2472
|
+
debugLog4(`[ACCOUNTS] Loaded ${manager.getAccountCount()} accounts from storage`);
|
|
2473
|
+
}
|
|
2474
|
+
} catch (error) {
|
|
2475
|
+
debugLog4(`[ACCOUNTS] Failed to load accounts, falling back to single-account: ${error instanceof Error ? error.message : "Unknown"}`);
|
|
2476
|
+
}
|
|
2477
|
+
accountsLoaded = true;
|
|
2478
|
+
}
|
|
2479
|
+
let currentAccount = null;
|
|
2480
|
+
if (manager) {
|
|
2481
|
+
const family = getModelFamily(url, init);
|
|
2482
|
+
currentAccount = manager.getCurrentOrNextForFamily(family);
|
|
2483
|
+
if (currentAccount) {
|
|
2484
|
+
debugLog4(`[ACCOUNTS] Using account ${currentAccount.index + 1}/${manager.getAccountCount()} for ${family}`);
|
|
2485
|
+
if (lastAccountIndex === null || lastAccountIndex !== currentAccount.index) {
|
|
2486
|
+
if (lastAccountIndex !== null) {
|
|
2487
|
+
debugLog4(`[ACCOUNTS] Account changed from ${lastAccountIndex + 1} to ${currentAccount.index + 1}, clearing cached state`);
|
|
2488
|
+
} else if (cachedProjectId) {
|
|
2489
|
+
debugLog4(`[ACCOUNTS] First account introduced, clearing cached state`);
|
|
2490
|
+
}
|
|
2491
|
+
cachedProjectId = null;
|
|
2492
|
+
cachedTokens = null;
|
|
2493
|
+
}
|
|
2494
|
+
lastAccountIndex = currentAccount.index;
|
|
2495
|
+
if (currentAccount.access && currentAccount.expires) {
|
|
2496
|
+
auth.access = currentAccount.access;
|
|
2497
|
+
auth.expires = currentAccount.expires;
|
|
2498
|
+
}
|
|
2499
|
+
refreshParts = {
|
|
2500
|
+
refreshToken: currentAccount.parts.refreshToken,
|
|
2501
|
+
projectId: currentAccount.parts.projectId,
|
|
2502
|
+
managedProjectId: currentAccount.parts.managedProjectId
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
if (!cachedTokens) {
|
|
2507
|
+
cachedTokens = {
|
|
2508
|
+
type: "antigravity",
|
|
2509
|
+
access_token: auth.access,
|
|
2510
|
+
refresh_token: refreshParts.refreshToken,
|
|
2511
|
+
expires_in: auth.expires ? Math.floor((auth.expires - Date.now()) / 1000) : 3600,
|
|
2512
|
+
timestamp: auth.expires ? auth.expires - 3600 * 1000 : Date.now()
|
|
2513
|
+
};
|
|
2514
|
+
} else {
|
|
2515
|
+
cachedTokens.access_token = auth.access;
|
|
2516
|
+
cachedTokens.refresh_token = refreshParts.refreshToken;
|
|
2517
|
+
}
|
|
2518
|
+
if (isTokenExpired(cachedTokens)) {
|
|
2519
|
+
debugLog4("Token expired, refreshing...");
|
|
2520
|
+
try {
|
|
2521
|
+
const newTokens = await refreshAccessToken(refreshParts.refreshToken, clientId, clientSecret);
|
|
2522
|
+
cachedTokens = {
|
|
2523
|
+
type: "antigravity",
|
|
2524
|
+
access_token: newTokens.access_token,
|
|
2525
|
+
refresh_token: newTokens.refresh_token,
|
|
2526
|
+
expires_in: newTokens.expires_in,
|
|
2527
|
+
timestamp: Date.now()
|
|
2528
|
+
};
|
|
2529
|
+
clearProjectContextCache();
|
|
2530
|
+
const formattedRefresh = formatTokenForStorage(newTokens.refresh_token, refreshParts.projectId || "", refreshParts.managedProjectId);
|
|
2531
|
+
await client.set(providerId, {
|
|
2532
|
+
access: newTokens.access_token,
|
|
2533
|
+
refresh: formattedRefresh,
|
|
2534
|
+
expires: Date.now() + newTokens.expires_in * 1000
|
|
2535
|
+
});
|
|
2536
|
+
debugLog4("Token refreshed successfully");
|
|
2537
|
+
} catch (error) {
|
|
2538
|
+
if (error instanceof AntigravityTokenRefreshError) {
|
|
2539
|
+
if (error.isInvalidGrant) {
|
|
2540
|
+
debugLog4(`[REFRESH] Token revoked (invalid_grant), clearing caches`);
|
|
2541
|
+
invalidateProjectContextByRefreshToken(refreshParts.refreshToken);
|
|
2542
|
+
clearProjectContextCache();
|
|
2543
|
+
}
|
|
2544
|
+
throw new Error(`Antigravity: Token refresh failed: ${error.description || error.message}${error.code ? ` (${error.code})` : ""}`);
|
|
2545
|
+
}
|
|
2546
|
+
throw new Error(`Antigravity: Token refresh failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
if (!cachedProjectId) {
|
|
2550
|
+
const projectContext = await fetchProjectContext(cachedTokens.access_token);
|
|
2551
|
+
cachedProjectId = projectContext.cloudaicompanionProject || "";
|
|
2552
|
+
debugLog4(`[PROJECT] Fetched project ID: "${cachedProjectId}"`);
|
|
2553
|
+
}
|
|
2554
|
+
const projectId = cachedProjectId;
|
|
2555
|
+
debugLog4(`[PROJECT] Using project ID: "${projectId}"`);
|
|
2556
|
+
let modelName;
|
|
2557
|
+
if (init.body) {
|
|
2558
|
+
try {
|
|
2559
|
+
const body = typeof init.body === "string" ? JSON.parse(init.body) : init.body;
|
|
2560
|
+
if (typeof body.model === "string") {
|
|
2561
|
+
modelName = body.model;
|
|
2562
|
+
}
|
|
2563
|
+
} catch {}
|
|
2564
|
+
}
|
|
2565
|
+
const maxEndpoints = Math.min(ANTIGRAVITY_ENDPOINT_FALLBACKS.length, 3);
|
|
2566
|
+
const sessionId = getOrCreateSessionId(fetchInstanceId);
|
|
2567
|
+
const thoughtSignature = getThoughtSignature(fetchInstanceId);
|
|
2568
|
+
debugLog4(`[TSIG][GET] sessionId=${sessionId}, signature=${thoughtSignature ? thoughtSignature.substring(0, 20) + "..." : "none"}`);
|
|
2569
|
+
let hasRefreshedFor401 = false;
|
|
2570
|
+
const executeWithEndpoints = async () => {
|
|
2571
|
+
for (let i = 0;i < maxEndpoints; i++) {
|
|
2572
|
+
const endpoint = ANTIGRAVITY_ENDPOINT_FALLBACKS[i];
|
|
2573
|
+
const response = await attemptFetch({
|
|
2574
|
+
endpoint,
|
|
2575
|
+
url,
|
|
2576
|
+
init,
|
|
2577
|
+
accessToken: cachedTokens.access_token,
|
|
2578
|
+
projectId,
|
|
2579
|
+
sessionId,
|
|
2580
|
+
modelName,
|
|
2581
|
+
thoughtSignature
|
|
2582
|
+
});
|
|
2583
|
+
if (response === "pass-through") {
|
|
2584
|
+
debugLog4("Non-string body detected, passing through with auth headers");
|
|
2585
|
+
const headersWithAuth = {
|
|
2586
|
+
...init.headers,
|
|
2587
|
+
Authorization: `Bearer ${cachedTokens.access_token}`
|
|
2588
|
+
};
|
|
2589
|
+
return fetch(url, { ...init, headers: headersWithAuth });
|
|
2590
|
+
}
|
|
2591
|
+
if (response === "needs-refresh") {
|
|
2592
|
+
if (hasRefreshedFor401) {
|
|
2593
|
+
debugLog4("[401] Already refreshed once, returning unauthorized error");
|
|
2594
|
+
return new Response(JSON.stringify({
|
|
2595
|
+
error: {
|
|
2596
|
+
message: "Authentication failed after token refresh",
|
|
2597
|
+
type: "unauthorized",
|
|
2598
|
+
code: "token_refresh_failed"
|
|
2599
|
+
}
|
|
2600
|
+
}), {
|
|
2601
|
+
status: 401,
|
|
2602
|
+
statusText: "Unauthorized",
|
|
2603
|
+
headers: { "Content-Type": "application/json" }
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
debugLog4("[401] Refreshing token and retrying...");
|
|
2607
|
+
hasRefreshedFor401 = true;
|
|
2608
|
+
try {
|
|
2609
|
+
const newTokens = await refreshAccessToken(refreshParts.refreshToken, clientId, clientSecret);
|
|
2610
|
+
cachedTokens = {
|
|
2611
|
+
type: "antigravity",
|
|
2612
|
+
access_token: newTokens.access_token,
|
|
2613
|
+
refresh_token: newTokens.refresh_token,
|
|
2614
|
+
expires_in: newTokens.expires_in,
|
|
2615
|
+
timestamp: Date.now()
|
|
2616
|
+
};
|
|
2617
|
+
clearProjectContextCache();
|
|
2618
|
+
const formattedRefresh = formatTokenForStorage(newTokens.refresh_token, refreshParts.projectId || "", refreshParts.managedProjectId);
|
|
2619
|
+
await client.set(providerId, {
|
|
2620
|
+
access: newTokens.access_token,
|
|
2621
|
+
refresh: formattedRefresh,
|
|
2622
|
+
expires: Date.now() + newTokens.expires_in * 1000
|
|
2623
|
+
});
|
|
2624
|
+
debugLog4("[401] Token refreshed, retrying request...");
|
|
2625
|
+
return executeWithEndpoints();
|
|
2626
|
+
} catch (refreshError) {
|
|
2627
|
+
if (refreshError instanceof AntigravityTokenRefreshError) {
|
|
2628
|
+
if (refreshError.isInvalidGrant) {
|
|
2629
|
+
debugLog4(`[401] Token revoked (invalid_grant), clearing caches`);
|
|
2630
|
+
invalidateProjectContextByRefreshToken(refreshParts.refreshToken);
|
|
2631
|
+
clearProjectContextCache();
|
|
2632
|
+
}
|
|
2633
|
+
debugLog4(`[401] Token refresh failed: ${refreshError.description || refreshError.message}`);
|
|
2634
|
+
return new Response(JSON.stringify({
|
|
2635
|
+
error: {
|
|
2636
|
+
message: refreshError.description || refreshError.message,
|
|
2637
|
+
type: refreshError.isInvalidGrant ? "token_revoked" : "unauthorized",
|
|
2638
|
+
code: refreshError.code || "token_refresh_failed"
|
|
2639
|
+
}
|
|
2640
|
+
}), {
|
|
2641
|
+
status: 401,
|
|
2642
|
+
statusText: "Unauthorized",
|
|
2643
|
+
headers: { "Content-Type": "application/json" }
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2646
|
+
debugLog4(`[401] Token refresh failed: ${refreshError instanceof Error ? refreshError.message : "Unknown error"}`);
|
|
2647
|
+
return new Response(JSON.stringify({
|
|
2648
|
+
error: {
|
|
2649
|
+
message: refreshError instanceof Error ? refreshError.message : "Unknown error",
|
|
2650
|
+
type: "unauthorized",
|
|
2651
|
+
code: "token_refresh_failed"
|
|
2652
|
+
}
|
|
2653
|
+
}), {
|
|
2654
|
+
status: 401,
|
|
2655
|
+
statusText: "Unauthorized",
|
|
2656
|
+
headers: { "Content-Type": "application/json" }
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
if (response && typeof response === "object" && "type" in response && response.type === "rate-limited") {
|
|
2661
|
+
const rateLimitInfo = response;
|
|
2662
|
+
const family = getModelFamily(url, init);
|
|
2663
|
+
if (rateLimitInfo.retryAfterMs > 5000 && manager && currentAccount) {
|
|
2664
|
+
manager.markRateLimited(currentAccount, rateLimitInfo.retryAfterMs, family);
|
|
2665
|
+
await manager.save();
|
|
2666
|
+
debugLog4(`[RATE-LIMIT] Account ${currentAccount.index + 1} rate-limited for ${family}, rotating...`);
|
|
2667
|
+
const nextAccount = manager.getCurrentOrNextForFamily(family);
|
|
2668
|
+
if (nextAccount && nextAccount.index !== currentAccount.index) {
|
|
2669
|
+
debugLog4(`[RATE-LIMIT] Switched to account ${nextAccount.index + 1}`);
|
|
2670
|
+
return fetchFn(url, init);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
const isLastEndpoint = i === maxEndpoints - 1;
|
|
2674
|
+
if (isLastEndpoint) {
|
|
2675
|
+
const isServerError = rateLimitInfo.status >= 500;
|
|
2676
|
+
debugLog4(`[RATE-LIMIT] No alternative account or endpoint, returning ${rateLimitInfo.status}`);
|
|
2677
|
+
return new Response(JSON.stringify({
|
|
2678
|
+
error: {
|
|
2679
|
+
message: isServerError ? `Server error (${rateLimitInfo.status}). Retry after ${Math.ceil(rateLimitInfo.retryAfterMs / 1000)} seconds` : `Rate limited. Retry after ${Math.ceil(rateLimitInfo.retryAfterMs / 1000)} seconds`,
|
|
2680
|
+
type: isServerError ? "server_error" : "rate_limit",
|
|
2681
|
+
code: isServerError ? "server_error" : "rate_limited"
|
|
2682
|
+
}
|
|
2683
|
+
}), {
|
|
2684
|
+
status: rateLimitInfo.status,
|
|
2685
|
+
statusText: isServerError ? "Server Error" : "Too Many Requests",
|
|
2686
|
+
headers: {
|
|
2687
|
+
"Content-Type": "application/json",
|
|
2688
|
+
"Retry-After": String(Math.ceil(rateLimitInfo.retryAfterMs / 1000))
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
}
|
|
2692
|
+
debugLog4(`[RATE-LIMIT] No alternative account available, trying next endpoint`);
|
|
2693
|
+
continue;
|
|
2694
|
+
}
|
|
2695
|
+
if (response && response instanceof Response) {
|
|
2696
|
+
debugLog4(`Success with endpoint: ${endpoint}`);
|
|
2697
|
+
const transformedResponse = await transformResponseWithThinking(response, modelName || "", fetchInstanceId);
|
|
2698
|
+
return transformedResponse;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
const errorMessage = `All Antigravity endpoints failed after ${maxEndpoints} attempts`;
|
|
2702
|
+
debugLog4(errorMessage);
|
|
2703
|
+
return new Response(JSON.stringify({
|
|
2704
|
+
error: {
|
|
2705
|
+
message: errorMessage,
|
|
2706
|
+
type: "endpoint_failure",
|
|
2707
|
+
code: "all_endpoints_failed"
|
|
2708
|
+
}
|
|
2709
|
+
}), {
|
|
2710
|
+
status: 503,
|
|
2711
|
+
statusText: "Service Unavailable",
|
|
2712
|
+
headers: { "Content-Type": "application/json" }
|
|
2713
|
+
});
|
|
2714
|
+
};
|
|
2715
|
+
return executeWithEndpoints();
|
|
2716
|
+
};
|
|
2717
|
+
return fetchFn;
|
|
2718
|
+
}
|
|
2719
|
+
// node_modules/@clack/prompts/node_modules/@clack/core/dist/index.mjs
|
|
2720
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2721
|
+
import { stdout as R, stdin as q } from "node:process";
|
|
2722
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
2723
|
+
import ot from "node:readline";
|
|
2724
|
+
var at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
|
|
2725
|
+
var lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
|
|
2726
|
+
var ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
|
|
2727
|
+
var O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
2728
|
+
var y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
2729
|
+
var M = /\t{1,1000}/y;
|
|
2730
|
+
var P = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
2731
|
+
var L = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
2732
|
+
var ct = /\p{M}+/gu;
|
|
2733
|
+
var Ft = { limit: 1 / 0, ellipsis: "" };
|
|
2734
|
+
var X = (t, e = {}, s = {}) => {
|
|
2735
|
+
const i = e.limit ?? 1 / 0, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X(r, Ft, s).width : 0), o = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
|
|
2736
|
+
let h = 0, u = 0, f = t.length, v = 0, p = false, d = f, b = Math.max(0, i - n), C = 0, B = 0, c = 0, F = 0;
|
|
2737
|
+
t:
|
|
2738
|
+
for (;; ) {
|
|
2739
|
+
if (B > C || u >= f && u > h) {
|
|
2740
|
+
const ut = t.slice(C, B) || t.slice(h, u);
|
|
2741
|
+
v = 0;
|
|
2742
|
+
for (const Y of ut.replaceAll(ct, "")) {
|
|
2743
|
+
const $ = Y.codePointAt(0) || 0;
|
|
2744
|
+
if (lt($) ? F = m : ht($) ? F = V : E !== A && at($) ? F = E : F = A, c + F > b && (d = Math.min(d, Math.max(C, h) + v)), c + F > i) {
|
|
2745
|
+
p = true;
|
|
2746
|
+
break t;
|
|
2747
|
+
}
|
|
2748
|
+
v += Y.length, c += F;
|
|
2749
|
+
}
|
|
2750
|
+
C = B = 0;
|
|
2751
|
+
}
|
|
2752
|
+
if (u >= f)
|
|
2753
|
+
break;
|
|
2754
|
+
if (L.lastIndex = u, L.test(t)) {
|
|
2755
|
+
if (v = L.lastIndex - u, F = v * A, c + F > b && (d = Math.min(d, u + Math.floor((b - c) / A))), c + F > i) {
|
|
2756
|
+
p = true;
|
|
2757
|
+
break;
|
|
2758
|
+
}
|
|
2759
|
+
c += F, C = h, B = u, u = h = L.lastIndex;
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
if (O.lastIndex = u, O.test(t)) {
|
|
2763
|
+
if (c + o > b && (d = Math.min(d, u)), c + o > i) {
|
|
2764
|
+
p = true;
|
|
2765
|
+
break;
|
|
2766
|
+
}
|
|
2767
|
+
c += o, C = h, B = u, u = h = O.lastIndex;
|
|
2768
|
+
continue;
|
|
2769
|
+
}
|
|
2770
|
+
if (y.lastIndex = u, y.test(t)) {
|
|
2771
|
+
if (v = y.lastIndex - u, F = v * a, c + F > b && (d = Math.min(d, u + Math.floor((b - c) / a))), c + F > i) {
|
|
2772
|
+
p = true;
|
|
2773
|
+
break;
|
|
2774
|
+
}
|
|
2775
|
+
c += F, C = h, B = u, u = h = y.lastIndex;
|
|
2776
|
+
continue;
|
|
2777
|
+
}
|
|
2778
|
+
if (M.lastIndex = u, M.test(t)) {
|
|
2779
|
+
if (v = M.lastIndex - u, F = v * l, c + F > b && (d = Math.min(d, u + Math.floor((b - c) / l))), c + F > i) {
|
|
2780
|
+
p = true;
|
|
2781
|
+
break;
|
|
2782
|
+
}
|
|
2783
|
+
c += F, C = h, B = u, u = h = M.lastIndex;
|
|
2784
|
+
continue;
|
|
2785
|
+
}
|
|
2786
|
+
if (P.lastIndex = u, P.test(t)) {
|
|
2787
|
+
if (c + g > b && (d = Math.min(d, u)), c + g > i) {
|
|
2788
|
+
p = true;
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
c += g, C = h, B = u, u = h = P.lastIndex;
|
|
2792
|
+
continue;
|
|
2793
|
+
}
|
|
2794
|
+
u += 1;
|
|
2795
|
+
}
|
|
2796
|
+
return { width: p ? b : c, index: p ? d : f, truncated: p, ellipsed: p && i >= n };
|
|
2797
|
+
};
|
|
2798
|
+
var ft = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
|
|
2799
|
+
var S = (t, e = {}) => X(t, ft, e).width;
|
|
2800
|
+
var W = "\x1B";
|
|
2801
|
+
var Z = "";
|
|
2802
|
+
var pt = 39;
|
|
2803
|
+
var j = "\x07";
|
|
2804
|
+
var Q = "[";
|
|
2805
|
+
var dt = "]";
|
|
2806
|
+
var tt = "m";
|
|
2807
|
+
var U = `${dt}8;;`;
|
|
2808
|
+
var et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
|
|
2809
|
+
var mt = (t) => {
|
|
2810
|
+
if (t >= 30 && t <= 37 || t >= 90 && t <= 97)
|
|
2811
|
+
return 39;
|
|
2812
|
+
if (t >= 40 && t <= 47 || t >= 100 && t <= 107)
|
|
2813
|
+
return 49;
|
|
2814
|
+
if (t === 1 || t === 2)
|
|
2815
|
+
return 22;
|
|
2816
|
+
if (t === 3)
|
|
2817
|
+
return 23;
|
|
2818
|
+
if (t === 4)
|
|
2819
|
+
return 24;
|
|
2820
|
+
if (t === 7)
|
|
2821
|
+
return 27;
|
|
2822
|
+
if (t === 8)
|
|
2823
|
+
return 28;
|
|
2824
|
+
if (t === 9)
|
|
2825
|
+
return 29;
|
|
2826
|
+
if (t === 0)
|
|
2827
|
+
return 0;
|
|
2828
|
+
};
|
|
2829
|
+
var st = (t) => `${W}${Q}${t}${tt}`;
|
|
2830
|
+
var it = (t) => `${W}${U}${t}${j}`;
|
|
2831
|
+
var gt = (t) => t.map((e) => S(e));
|
|
2832
|
+
var G = (t, e, s) => {
|
|
2833
|
+
const i = e[Symbol.iterator]();
|
|
2834
|
+
let r = false, n = false, o = t.at(-1), a = o === undefined ? 0 : S(o), l = i.next(), E = i.next(), g = 0;
|
|
2835
|
+
for (;!l.done; ) {
|
|
2836
|
+
const m = l.value, A = S(m);
|
|
2837
|
+
a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = true, n = e.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
|
|
2838
|
+
}
|
|
2839
|
+
o = t.at(-1), !a && o !== undefined && o.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
|
|
2840
|
+
};
|
|
2841
|
+
var vt = (t) => {
|
|
2842
|
+
const e = t.split(" ");
|
|
2843
|
+
let s = e.length;
|
|
2844
|
+
for (;s > 0 && !(S(e[s - 1]) > 0); )
|
|
2845
|
+
s--;
|
|
2846
|
+
return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
|
|
2847
|
+
};
|
|
2848
|
+
var Et = (t, e, s = {}) => {
|
|
2849
|
+
if (s.trim !== false && t.trim() === "")
|
|
2850
|
+
return "";
|
|
2851
|
+
let i = "", r, n;
|
|
2852
|
+
const o = t.split(" "), a = gt(o);
|
|
2853
|
+
let l = [""];
|
|
2854
|
+
for (const [h, u] of o.entries()) {
|
|
2855
|
+
s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
|
|
2856
|
+
let f = S(l.at(-1) ?? "");
|
|
2857
|
+
if (h !== 0 && (f >= e && (s.wordWrap === false || s.trim === false) && (l.push(""), f = 0), (f > 0 || s.trim === false) && (l[l.length - 1] += " ", f++)), s.hard && a[h] > e) {
|
|
2858
|
+
const v = e - f, p = 1 + Math.floor((a[h] - v - 1) / e);
|
|
2859
|
+
Math.floor((a[h] - 1) / e) < p && l.push(""), G(l, u, e);
|
|
2860
|
+
continue;
|
|
2861
|
+
}
|
|
2862
|
+
if (f + a[h] > e && f > 0 && a[h] > 0) {
|
|
2863
|
+
if (s.wordWrap === false && f < e) {
|
|
2864
|
+
G(l, u, e);
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
l.push("");
|
|
2868
|
+
}
|
|
2869
|
+
if (f + a[h] > e && s.wordWrap === false) {
|
|
2870
|
+
G(l, u, e);
|
|
2871
|
+
continue;
|
|
2872
|
+
}
|
|
2873
|
+
l[l.length - 1] += u;
|
|
2874
|
+
}
|
|
2875
|
+
s.trim !== false && (l = l.map((h) => vt(h)));
|
|
2876
|
+
const E = l.join(`
|
|
2877
|
+
`), g = E[Symbol.iterator]();
|
|
2878
|
+
let m = g.next(), A = g.next(), V = 0;
|
|
2879
|
+
for (;!m.done; ) {
|
|
2880
|
+
const h = m.value, u = A.value;
|
|
2881
|
+
if (i += h, h === W || h === Z) {
|
|
2882
|
+
et.lastIndex = V + 1;
|
|
2883
|
+
const p = et.exec(E)?.groups;
|
|
2884
|
+
if (p?.code !== undefined) {
|
|
2885
|
+
const d = Number.parseFloat(p.code);
|
|
2886
|
+
r = d === pt ? undefined : d;
|
|
2887
|
+
} else
|
|
2888
|
+
p?.uri !== undefined && (n = p.uri.length === 0 ? undefined : p.uri);
|
|
2889
|
+
}
|
|
2890
|
+
const f = r ? mt(r) : undefined;
|
|
2891
|
+
u === `
|
|
2892
|
+
` ? (n && (i += it("")), r && f && (i += st(f))) : h === `
|
|
2893
|
+
` && (r && f && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
|
|
2894
|
+
}
|
|
2895
|
+
return i;
|
|
2896
|
+
};
|
|
2897
|
+
function K(t, e, s) {
|
|
2898
|
+
return String(t).normalize().replaceAll(`\r
|
|
2899
|
+
`, `
|
|
2900
|
+
`).split(`
|
|
2901
|
+
`).map((i) => Et(i, e, s)).join(`
|
|
2902
|
+
`);
|
|
2903
|
+
}
|
|
2904
|
+
var At = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
2905
|
+
var _ = { actions: new Set(At), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
|
|
2906
|
+
function H(t, e) {
|
|
2907
|
+
if (typeof t == "string")
|
|
2908
|
+
return _.aliases.get(t) === e;
|
|
2909
|
+
for (const s of t)
|
|
2910
|
+
if (s !== undefined && H(s, e))
|
|
2911
|
+
return true;
|
|
2912
|
+
return false;
|
|
2913
|
+
}
|
|
2914
|
+
function _t(t, e) {
|
|
2915
|
+
if (t === e)
|
|
2916
|
+
return;
|
|
2917
|
+
const s = t.split(`
|
|
2918
|
+
`), i = e.split(`
|
|
2919
|
+
`), r = Math.max(s.length, i.length), n = [];
|
|
2920
|
+
for (let o = 0;o < r; o++)
|
|
2921
|
+
s[o] !== i[o] && n.push(o);
|
|
2922
|
+
return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
|
|
2923
|
+
}
|
|
2924
|
+
var bt = globalThis.process.platform.startsWith("win");
|
|
2925
|
+
var z = Symbol("clack:cancel");
|
|
2926
|
+
function Ct(t) {
|
|
2927
|
+
return t === z;
|
|
2928
|
+
}
|
|
2929
|
+
function T(t, e) {
|
|
2930
|
+
const s = t;
|
|
2931
|
+
s.isTTY && s.setRawMode(e);
|
|
2932
|
+
}
|
|
2933
|
+
var rt = (t) => ("columns" in t) && typeof t.columns == "number" ? t.columns : 80;
|
|
2934
|
+
var nt = (t) => ("rows" in t) && typeof t.rows == "number" ? t.rows : 20;
|
|
2935
|
+
function Bt(t, e, s, i = s) {
|
|
2936
|
+
const r = rt(t ?? R);
|
|
2937
|
+
return K(e, r - s.length, { hard: true, trim: false }).split(`
|
|
2938
|
+
`).map((n, o) => `${o === 0 ? i : s}${n}`).join(`
|
|
2939
|
+
`);
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
class x {
|
|
2943
|
+
input;
|
|
2944
|
+
output;
|
|
2945
|
+
_abortSignal;
|
|
2946
|
+
rl;
|
|
2947
|
+
opts;
|
|
2948
|
+
_render;
|
|
2949
|
+
_track = false;
|
|
2950
|
+
_prevFrame = "";
|
|
2951
|
+
_subscribers = new Map;
|
|
2952
|
+
_cursor = 0;
|
|
2953
|
+
state = "initial";
|
|
2954
|
+
error = "";
|
|
2955
|
+
value;
|
|
2956
|
+
userInput = "";
|
|
2957
|
+
constructor(e, s = true) {
|
|
2958
|
+
const { input: i = q, output: r = R, render: n, signal: o, ...a } = e;
|
|
2959
|
+
this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = o, this.input = i, this.output = r;
|
|
2960
|
+
}
|
|
2961
|
+
unsubscribe() {
|
|
2962
|
+
this._subscribers.clear();
|
|
2963
|
+
}
|
|
2964
|
+
setSubscriber(e, s) {
|
|
2965
|
+
const i = this._subscribers.get(e) ?? [];
|
|
2966
|
+
i.push(s), this._subscribers.set(e, i);
|
|
2967
|
+
}
|
|
2968
|
+
on(e, s) {
|
|
2969
|
+
this.setSubscriber(e, { cb: s });
|
|
2970
|
+
}
|
|
2971
|
+
once(e, s) {
|
|
2972
|
+
this.setSubscriber(e, { cb: s, once: true });
|
|
2973
|
+
}
|
|
2974
|
+
emit(e, ...s) {
|
|
2975
|
+
const i = this._subscribers.get(e) ?? [], r = [];
|
|
2976
|
+
for (const n of i)
|
|
2977
|
+
n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
|
|
2978
|
+
for (const n of r)
|
|
2979
|
+
n();
|
|
2980
|
+
}
|
|
2981
|
+
prompt() {
|
|
2982
|
+
return new Promise((e) => {
|
|
2983
|
+
if (this._abortSignal) {
|
|
2984
|
+
if (this._abortSignal.aborted)
|
|
2985
|
+
return this.state = "cancel", this.close(), e(z);
|
|
2986
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
2987
|
+
this.state = "cancel", this.close();
|
|
2988
|
+
}, { once: true });
|
|
2989
|
+
}
|
|
2990
|
+
this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), T(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
2991
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(this.value);
|
|
2992
|
+
}), this.once("cancel", () => {
|
|
2993
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(z);
|
|
2994
|
+
});
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
_isActionKey(e, s) {
|
|
2998
|
+
return e === "\t";
|
|
2999
|
+
}
|
|
3000
|
+
_setValue(e) {
|
|
3001
|
+
this.value = e, this.emit("value", this.value);
|
|
3002
|
+
}
|
|
3003
|
+
_setUserInput(e, s) {
|
|
3004
|
+
this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
3005
|
+
}
|
|
3006
|
+
_clearUserInput() {
|
|
3007
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
3008
|
+
}
|
|
3009
|
+
onKeypress(e, s) {
|
|
3010
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
|
|
3011
|
+
if (this.opts.validate) {
|
|
3012
|
+
const i = this.opts.validate(this.value);
|
|
3013
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
3014
|
+
}
|
|
3015
|
+
this.state !== "error" && (this.state = "submit");
|
|
3016
|
+
}
|
|
3017
|
+
H([e, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
3018
|
+
}
|
|
3019
|
+
close() {
|
|
3020
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
3021
|
+
`), T(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
3022
|
+
}
|
|
3023
|
+
restoreCursor() {
|
|
3024
|
+
const e = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
3025
|
+
`).length - 1;
|
|
3026
|
+
this.output.write(import_sisteransi.cursor.move(-999, e * -1));
|
|
3027
|
+
}
|
|
3028
|
+
render() {
|
|
3029
|
+
const e = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
|
|
3030
|
+
if (e !== this._prevFrame) {
|
|
3031
|
+
if (this.state === "initial")
|
|
3032
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
3033
|
+
else {
|
|
3034
|
+
const s = _t(this._prevFrame, e), i = nt(this.output);
|
|
3035
|
+
if (this.restoreCursor(), s) {
|
|
3036
|
+
const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
|
|
3037
|
+
let o = s.lines.find((a) => a >= r);
|
|
3038
|
+
if (o === undefined) {
|
|
3039
|
+
this._prevFrame = e;
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
if (s.lines.length === 1) {
|
|
3043
|
+
this.output.write(import_sisteransi.cursor.move(0, o - n)), this.output.write(import_sisteransi.erase.lines(1));
|
|
3044
|
+
const a = e.split(`
|
|
3045
|
+
`);
|
|
3046
|
+
this.output.write(a[o]), this._prevFrame = e, this.output.write(import_sisteransi.cursor.move(0, a.length - o - 1));
|
|
3047
|
+
return;
|
|
3048
|
+
} else if (s.lines.length > 1) {
|
|
3049
|
+
if (r < n)
|
|
3050
|
+
o = r;
|
|
3051
|
+
else {
|
|
3052
|
+
const l = o - n;
|
|
3053
|
+
l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
|
|
3054
|
+
}
|
|
3055
|
+
this.output.write(import_sisteransi.erase.down());
|
|
3056
|
+
const a = e.split(`
|
|
3057
|
+
`).slice(o);
|
|
3058
|
+
this.output.write(a.join(`
|
|
3059
|
+
`)), this._prevFrame = e;
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
this.output.write(import_sisteransi.erase.down());
|
|
3064
|
+
}
|
|
3065
|
+
this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
function wt(t, e) {
|
|
3070
|
+
if (t === undefined || e.length === 0)
|
|
3071
|
+
return 0;
|
|
3072
|
+
const s = e.findIndex((i) => i.value === t);
|
|
3073
|
+
return s !== -1 ? s : 0;
|
|
3074
|
+
}
|
|
3075
|
+
function Dt(t, e) {
|
|
3076
|
+
return (e.label ?? String(e.value)).toLowerCase().includes(t.toLowerCase());
|
|
3077
|
+
}
|
|
3078
|
+
function St(t, e) {
|
|
3079
|
+
if (e)
|
|
3080
|
+
return t ? e : e[0];
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
class Vt extends x {
|
|
3084
|
+
filteredOptions;
|
|
3085
|
+
multiple;
|
|
3086
|
+
isNavigating = false;
|
|
3087
|
+
selectedValues = [];
|
|
3088
|
+
focusedValue;
|
|
3089
|
+
#t = 0;
|
|
3090
|
+
#s = "";
|
|
3091
|
+
#i;
|
|
3092
|
+
#e;
|
|
3093
|
+
get cursor() {
|
|
3094
|
+
return this.#t;
|
|
3095
|
+
}
|
|
3096
|
+
get userInputWithCursor() {
|
|
3097
|
+
if (!this.userInput)
|
|
3098
|
+
return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
|
|
3099
|
+
if (this._cursor >= this.userInput.length)
|
|
3100
|
+
return `${this.userInput}█`;
|
|
3101
|
+
const e = this.userInput.slice(0, this._cursor), [s, ...i] = this.userInput.slice(this._cursor);
|
|
3102
|
+
return `${e}${import_picocolors.default.inverse(s)}${i.join("")}`;
|
|
3103
|
+
}
|
|
3104
|
+
get options() {
|
|
3105
|
+
return typeof this.#e == "function" ? this.#e() : this.#e;
|
|
3106
|
+
}
|
|
3107
|
+
constructor(e) {
|
|
3108
|
+
super(e), this.#e = e.options;
|
|
3109
|
+
const s = this.options;
|
|
3110
|
+
this.filteredOptions = [...s], this.multiple = e.multiple === true, this.#i = e.filter ?? Dt;
|
|
3111
|
+
let i;
|
|
3112
|
+
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
|
|
3113
|
+
for (const r of i) {
|
|
3114
|
+
const n = s.findIndex((o) => o.value === r);
|
|
3115
|
+
n !== -1 && (this.toggleSelected(r), this.#t = n);
|
|
3116
|
+
}
|
|
3117
|
+
this.focusedValue = this.options[this.#t]?.value, this.on("key", (r, n) => this.#r(r, n)), this.on("userInput", (r) => this.#n(r));
|
|
3118
|
+
}
|
|
3119
|
+
_isActionKey(e, s) {
|
|
3120
|
+
return e === "\t" || this.multiple && this.isNavigating && s.name === "space" && e !== undefined && e !== "";
|
|
3121
|
+
}
|
|
3122
|
+
#r(e, s) {
|
|
3123
|
+
const i = s.name === "up", r = s.name === "down", n = s.name === "return";
|
|
3124
|
+
i || r ? (this.#t = Math.max(0, Math.min(this.#t + (i ? -1 : 1), this.filteredOptions.length - 1)), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = St(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
3125
|
+
}
|
|
3126
|
+
deselectAll() {
|
|
3127
|
+
this.selectedValues = [];
|
|
3128
|
+
}
|
|
3129
|
+
toggleSelected(e) {
|
|
3130
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((s) => s !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
3131
|
+
}
|
|
3132
|
+
#n(e) {
|
|
3133
|
+
if (e !== this.#s) {
|
|
3134
|
+
this.#s = e;
|
|
3135
|
+
const s = this.options;
|
|
3136
|
+
e ? this.filteredOptions = s.filter((i) => this.#i(e, i)) : this.filteredOptions = [...s], this.#t = wt(this.focusedValue, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
var kt = class extends x {
|
|
3141
|
+
get cursor() {
|
|
3142
|
+
return this.value ? 0 : 1;
|
|
3143
|
+
}
|
|
3144
|
+
get _value() {
|
|
3145
|
+
return this.cursor === 0;
|
|
3146
|
+
}
|
|
3147
|
+
constructor(e) {
|
|
3148
|
+
super(e, false), this.value = !!e.initialValue, this.on("userInput", () => {
|
|
3149
|
+
this.value = this._value;
|
|
3150
|
+
}), this.on("confirm", (s) => {
|
|
3151
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
|
|
3152
|
+
}), this.on("cursor", () => {
|
|
3153
|
+
this.value = !this.value;
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
class yt extends x {
|
|
3159
|
+
options;
|
|
3160
|
+
cursor = 0;
|
|
3161
|
+
#t;
|
|
3162
|
+
getGroupItems(e) {
|
|
3163
|
+
return this.options.filter((s) => s.group === e);
|
|
3164
|
+
}
|
|
3165
|
+
isGroupSelected(e) {
|
|
3166
|
+
const s = this.getGroupItems(e), i = this.value;
|
|
3167
|
+
return i === undefined ? false : s.every((r) => i.includes(r.value));
|
|
3168
|
+
}
|
|
3169
|
+
toggleValue() {
|
|
3170
|
+
const e = this.options[this.cursor];
|
|
3171
|
+
if (this.value === undefined && (this.value = []), e.group === true) {
|
|
3172
|
+
const s = e.value, i = this.getGroupItems(s);
|
|
3173
|
+
this.isGroupSelected(s) ? this.value = this.value.filter((r) => i.findIndex((n) => n.value === r) === -1) : this.value = [...this.value, ...i.map((r) => r.value)], this.value = Array.from(new Set(this.value));
|
|
3174
|
+
} else {
|
|
3175
|
+
const s = this.value.includes(e.value);
|
|
3176
|
+
this.value = s ? this.value.filter((i) => i !== e.value) : [...this.value, e.value];
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
constructor(e) {
|
|
3180
|
+
super(e, false);
|
|
3181
|
+
const { options: s } = e;
|
|
3182
|
+
this.#t = e.selectableGroups !== false, this.options = Object.entries(s).flatMap(([i, r]) => [{ value: i, group: true, label: i }, ...r.map((n) => ({ ...n, group: i }))]), this.value = [...e.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), this.#t ? 0 : 1), this.on("cursor", (i) => {
|
|
3183
|
+
switch (i) {
|
|
3184
|
+
case "left":
|
|
3185
|
+
case "up": {
|
|
3186
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
3187
|
+
const r = this.options[this.cursor]?.group === true;
|
|
3188
|
+
!this.#t && r && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
3189
|
+
break;
|
|
3190
|
+
}
|
|
3191
|
+
case "down":
|
|
3192
|
+
case "right": {
|
|
3193
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
3194
|
+
const r = this.options[this.cursor]?.group === true;
|
|
3195
|
+
!this.#t && r && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
3196
|
+
break;
|
|
3197
|
+
}
|
|
3198
|
+
case "space":
|
|
3199
|
+
this.toggleValue();
|
|
3200
|
+
break;
|
|
3201
|
+
}
|
|
3202
|
+
});
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
function D(t, e, s) {
|
|
3206
|
+
const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
|
|
3207
|
+
return s[n].disabled ? D(n, e < 0 ? -1 : 1, s) : n;
|
|
3208
|
+
}
|
|
3209
|
+
class Wt extends x {
|
|
3210
|
+
options;
|
|
3211
|
+
cursor = 0;
|
|
3212
|
+
get _selectedValue() {
|
|
3213
|
+
return this.options[this.cursor];
|
|
3214
|
+
}
|
|
3215
|
+
changeValue() {
|
|
3216
|
+
this.value = this._selectedValue.value;
|
|
3217
|
+
}
|
|
3218
|
+
constructor(e) {
|
|
3219
|
+
super(e, false), this.options = e.options;
|
|
3220
|
+
const s = this.options.findIndex(({ value: r }) => r === e.initialValue), i = s === -1 ? 0 : s;
|
|
3221
|
+
this.cursor = this.options[i].disabled ? D(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
|
|
3222
|
+
switch (r) {
|
|
3223
|
+
case "left":
|
|
3224
|
+
case "up":
|
|
3225
|
+
this.cursor = D(this.cursor, -1, this.options);
|
|
3226
|
+
break;
|
|
3227
|
+
case "down":
|
|
3228
|
+
case "right":
|
|
3229
|
+
this.cursor = D(this.cursor, 1, this.options);
|
|
3230
|
+
break;
|
|
3231
|
+
}
|
|
3232
|
+
this.changeValue();
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
3238
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
3239
|
+
import P2 from "node:process";
|
|
3240
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
3241
|
+
function ht2() {
|
|
3242
|
+
return P2.platform !== "win32" ? P2.env.TERM !== "linux" : !!P2.env.CI || !!P2.env.WT_SESSION || !!P2.env.TERMINUS_SUBLIME || P2.env.ConEmuTask === "{cmd::Cmder}" || P2.env.TERM_PROGRAM === "Terminus-Sublime" || P2.env.TERM_PROGRAM === "vscode" || P2.env.TERM === "xterm-256color" || P2.env.TERM === "alacritty" || P2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
3243
|
+
}
|
|
3244
|
+
var ee = ht2();
|
|
3245
|
+
var w2 = (e, r) => ee ? e : r;
|
|
3246
|
+
var Me = w2("◆", "*");
|
|
3247
|
+
var ce = w2("■", "x");
|
|
3248
|
+
var de = w2("▲", "x");
|
|
3249
|
+
var V = w2("◇", "o");
|
|
3250
|
+
var $e = w2("┌", "T");
|
|
3251
|
+
var h = w2("│", "|");
|
|
3252
|
+
var x2 = w2("└", "—");
|
|
3253
|
+
var Re = w2("┐", "T");
|
|
3254
|
+
var Oe = w2("┘", "—");
|
|
3255
|
+
var Y = w2("●", ">");
|
|
3256
|
+
var K2 = w2("○", " ");
|
|
3257
|
+
var te = w2("◻", "[•]");
|
|
3258
|
+
var k = w2("◼", "[+]");
|
|
3259
|
+
var z2 = w2("◻", "[ ]");
|
|
3260
|
+
var Pe = w2("▪", "•");
|
|
3261
|
+
var se = w2("─", "-");
|
|
3262
|
+
var he = w2("╮", "+");
|
|
3263
|
+
var Ne = w2("├", "+");
|
|
3264
|
+
var me = w2("╯", "+");
|
|
3265
|
+
var pe = w2("╰", "+");
|
|
3266
|
+
var We = w2("╭", "+");
|
|
3267
|
+
var ge = w2("●", "•");
|
|
3268
|
+
var fe = w2("◆", "*");
|
|
3269
|
+
var Fe = w2("▲", "!");
|
|
3270
|
+
var ye = w2("■", "x");
|
|
3271
|
+
var N2 = (e) => {
|
|
3272
|
+
switch (e) {
|
|
3273
|
+
case "initial":
|
|
3274
|
+
case "active":
|
|
3275
|
+
return import_picocolors2.default.cyan(Me);
|
|
3276
|
+
case "cancel":
|
|
3277
|
+
return import_picocolors2.default.red(ce);
|
|
3278
|
+
case "error":
|
|
3279
|
+
return import_picocolors2.default.yellow(de);
|
|
3280
|
+
case "submit":
|
|
3281
|
+
return import_picocolors2.default.green(V);
|
|
3282
|
+
}
|
|
3283
|
+
};
|
|
3284
|
+
var Ee = (e) => {
|
|
3285
|
+
switch (e) {
|
|
3286
|
+
case "initial":
|
|
3287
|
+
case "active":
|
|
3288
|
+
return import_picocolors2.default.cyan(h);
|
|
3289
|
+
case "cancel":
|
|
3290
|
+
return import_picocolors2.default.red(h);
|
|
3291
|
+
case "error":
|
|
3292
|
+
return import_picocolors2.default.yellow(h);
|
|
3293
|
+
case "submit":
|
|
3294
|
+
return import_picocolors2.default.green(h);
|
|
3295
|
+
}
|
|
3296
|
+
};
|
|
3297
|
+
var mt2 = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109;
|
|
3298
|
+
var pt2 = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510;
|
|
3299
|
+
var gt2 = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141;
|
|
3300
|
+
var ve = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
3301
|
+
var re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
3302
|
+
var ie = /\t{1,1000}/y;
|
|
3303
|
+
var Ae = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
3304
|
+
var ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
3305
|
+
var ft2 = /\p{M}+/gu;
|
|
3306
|
+
var Ft2 = { limit: 1 / 0, ellipsis: "" };
|
|
3307
|
+
var Le = (e, r = {}, s = {}) => {
|
|
3308
|
+
const i = r.limit ?? 1 / 0, n = r.ellipsis ?? "", l = r?.ellipsisWidth ?? (n ? Le(n, Ft2, s).width : 0), u = s.ansiWidth ?? 0, o = s.controlWidth ?? 0, a = s.tabWidth ?? 8, c = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, E = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, y2 = s.wideWidth ?? 2;
|
|
3309
|
+
let $ = 0, m = 0, d = e.length, F = 0, f = false, v = d, I2 = Math.max(0, i - l), B = 0, b = 0, A = 0, C = 0;
|
|
3310
|
+
e:
|
|
3311
|
+
for (;; ) {
|
|
3312
|
+
if (b > B || m >= d && m > $) {
|
|
3313
|
+
const _2 = e.slice(B, b) || e.slice($, m);
|
|
3314
|
+
F = 0;
|
|
3315
|
+
for (const D2 of _2.replaceAll(ft2, "")) {
|
|
3316
|
+
const T2 = D2.codePointAt(0) || 0;
|
|
3317
|
+
if (pt2(T2) ? C = E : gt2(T2) ? C = y2 : c !== p && mt2(T2) ? C = c : C = p, A + C > I2 && (v = Math.min(v, Math.max(B, $) + F)), A + C > i) {
|
|
3318
|
+
f = true;
|
|
3319
|
+
break e;
|
|
3320
|
+
}
|
|
3321
|
+
F += D2.length, A += C;
|
|
3322
|
+
}
|
|
3323
|
+
B = b = 0;
|
|
3324
|
+
}
|
|
3325
|
+
if (m >= d)
|
|
3326
|
+
break;
|
|
3327
|
+
if (ne.lastIndex = m, ne.test(e)) {
|
|
3328
|
+
if (F = ne.lastIndex - m, C = F * p, A + C > I2 && (v = Math.min(v, m + Math.floor((I2 - A) / p))), A + C > i) {
|
|
3329
|
+
f = true;
|
|
3330
|
+
break;
|
|
3331
|
+
}
|
|
3332
|
+
A += C, B = $, b = m, m = $ = ne.lastIndex;
|
|
3333
|
+
continue;
|
|
3334
|
+
}
|
|
3335
|
+
if (ve.lastIndex = m, ve.test(e)) {
|
|
3336
|
+
if (A + u > I2 && (v = Math.min(v, m)), A + u > i) {
|
|
3337
|
+
f = true;
|
|
3338
|
+
break;
|
|
3339
|
+
}
|
|
3340
|
+
A += u, B = $, b = m, m = $ = ve.lastIndex;
|
|
3341
|
+
continue;
|
|
3342
|
+
}
|
|
3343
|
+
if (re.lastIndex = m, re.test(e)) {
|
|
3344
|
+
if (F = re.lastIndex - m, C = F * o, A + C > I2 && (v = Math.min(v, m + Math.floor((I2 - A) / o))), A + C > i) {
|
|
3345
|
+
f = true;
|
|
3346
|
+
break;
|
|
3347
|
+
}
|
|
3348
|
+
A += C, B = $, b = m, m = $ = re.lastIndex;
|
|
3349
|
+
continue;
|
|
3350
|
+
}
|
|
3351
|
+
if (ie.lastIndex = m, ie.test(e)) {
|
|
3352
|
+
if (F = ie.lastIndex - m, C = F * a, A + C > I2 && (v = Math.min(v, m + Math.floor((I2 - A) / a))), A + C > i) {
|
|
3353
|
+
f = true;
|
|
3354
|
+
break;
|
|
3355
|
+
}
|
|
3356
|
+
A += C, B = $, b = m, m = $ = ie.lastIndex;
|
|
3357
|
+
continue;
|
|
3358
|
+
}
|
|
3359
|
+
if (Ae.lastIndex = m, Ae.test(e)) {
|
|
3360
|
+
if (A + g > I2 && (v = Math.min(v, m)), A + g > i) {
|
|
3361
|
+
f = true;
|
|
3362
|
+
break;
|
|
3363
|
+
}
|
|
3364
|
+
A += g, B = $, b = m, m = $ = Ae.lastIndex;
|
|
3365
|
+
continue;
|
|
3366
|
+
}
|
|
3367
|
+
m += 1;
|
|
3368
|
+
}
|
|
3369
|
+
return { width: f ? I2 : A, index: f ? v : d, truncated: f, ellipsed: f && i >= l };
|
|
3370
|
+
};
|
|
3371
|
+
var yt2 = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
|
|
3372
|
+
var M2 = (e, r = {}) => Le(e, yt2, r).width;
|
|
3373
|
+
var ae = "\x1B";
|
|
3374
|
+
var je = "";
|
|
3375
|
+
var Et2 = 39;
|
|
3376
|
+
var Ce = "\x07";
|
|
3377
|
+
var Ve = "[";
|
|
3378
|
+
var vt2 = "]";
|
|
3379
|
+
var ke = "m";
|
|
3380
|
+
var we = `${vt2}8;;`;
|
|
3381
|
+
var Ge = new RegExp(`(?:\\${Ve}(?<code>\\d+)m|\\${we}(?<uri>.*)${Ce})`, "y");
|
|
3382
|
+
var At2 = (e) => {
|
|
3383
|
+
if (e >= 30 && e <= 37 || e >= 90 && e <= 97)
|
|
3384
|
+
return 39;
|
|
3385
|
+
if (e >= 40 && e <= 47 || e >= 100 && e <= 107)
|
|
3386
|
+
return 49;
|
|
3387
|
+
if (e === 1 || e === 2)
|
|
3388
|
+
return 22;
|
|
3389
|
+
if (e === 3)
|
|
3390
|
+
return 23;
|
|
3391
|
+
if (e === 4)
|
|
3392
|
+
return 24;
|
|
3393
|
+
if (e === 7)
|
|
3394
|
+
return 27;
|
|
3395
|
+
if (e === 8)
|
|
3396
|
+
return 28;
|
|
3397
|
+
if (e === 9)
|
|
3398
|
+
return 29;
|
|
3399
|
+
if (e === 0)
|
|
3400
|
+
return 0;
|
|
3401
|
+
};
|
|
3402
|
+
var He = (e) => `${ae}${Ve}${e}${ke}`;
|
|
3403
|
+
var Ue = (e) => `${ae}${we}${e}${Ce}`;
|
|
3404
|
+
var Ct2 = (e) => e.map((r) => M2(r));
|
|
3405
|
+
var Ie = (e, r, s) => {
|
|
3406
|
+
const i = r[Symbol.iterator]();
|
|
3407
|
+
let n = false, l = false, u = e.at(-1), o = u === undefined ? 0 : M2(u), a = i.next(), c = i.next(), g = 0;
|
|
3408
|
+
for (;!a.done; ) {
|
|
3409
|
+
const E = a.value, p = M2(E);
|
|
3410
|
+
o + p <= s ? e[e.length - 1] += E : (e.push(E), o = 0), (E === ae || E === je) && (n = true, l = r.startsWith(we, g + 1)), n ? l ? E === Ce && (n = false, l = false) : E === ke && (n = false) : (o += p, o === s && !c.done && (e.push(""), o = 0)), a = c, c = i.next(), g += E.length;
|
|
3411
|
+
}
|
|
3412
|
+
u = e.at(-1), !o && u !== undefined && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
|
|
3413
|
+
};
|
|
3414
|
+
var wt2 = (e) => {
|
|
3415
|
+
const r = e.split(" ");
|
|
3416
|
+
let s = r.length;
|
|
3417
|
+
for (;s > 0 && !(M2(r[s - 1]) > 0); )
|
|
3418
|
+
s--;
|
|
3419
|
+
return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
|
|
3420
|
+
};
|
|
3421
|
+
var It2 = (e, r, s = {}) => {
|
|
3422
|
+
if (s.trim !== false && e.trim() === "")
|
|
3423
|
+
return "";
|
|
3424
|
+
let i = "", n, l;
|
|
3425
|
+
const u = e.split(" "), o = Ct2(u);
|
|
3426
|
+
let a = [""];
|
|
3427
|
+
for (const [$, m] of u.entries()) {
|
|
3428
|
+
s.trim !== false && (a[a.length - 1] = (a.at(-1) ?? "").trimStart());
|
|
3429
|
+
let d = M2(a.at(-1) ?? "");
|
|
3430
|
+
if ($ !== 0 && (d >= r && (s.wordWrap === false || s.trim === false) && (a.push(""), d = 0), (d > 0 || s.trim === false) && (a[a.length - 1] += " ", d++)), s.hard && o[$] > r) {
|
|
3431
|
+
const F = r - d, f = 1 + Math.floor((o[$] - F - 1) / r);
|
|
3432
|
+
Math.floor((o[$] - 1) / r) < f && a.push(""), Ie(a, m, r);
|
|
3433
|
+
continue;
|
|
3434
|
+
}
|
|
3435
|
+
if (d + o[$] > r && d > 0 && o[$] > 0) {
|
|
3436
|
+
if (s.wordWrap === false && d < r) {
|
|
3437
|
+
Ie(a, m, r);
|
|
3438
|
+
continue;
|
|
3439
|
+
}
|
|
3440
|
+
a.push("");
|
|
3441
|
+
}
|
|
3442
|
+
if (d + o[$] > r && s.wordWrap === false) {
|
|
3443
|
+
Ie(a, m, r);
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
a[a.length - 1] += m;
|
|
3447
|
+
}
|
|
3448
|
+
s.trim !== false && (a = a.map(($) => wt2($)));
|
|
3449
|
+
const c = a.join(`
|
|
3450
|
+
`), g = c[Symbol.iterator]();
|
|
3451
|
+
let E = g.next(), p = g.next(), y2 = 0;
|
|
3452
|
+
for (;!E.done; ) {
|
|
3453
|
+
const $ = E.value, m = p.value;
|
|
3454
|
+
if (i += $, $ === ae || $ === je) {
|
|
3455
|
+
Ge.lastIndex = y2 + 1;
|
|
3456
|
+
const f = Ge.exec(c)?.groups;
|
|
3457
|
+
if (f?.code !== undefined) {
|
|
3458
|
+
const v = Number.parseFloat(f.code);
|
|
3459
|
+
n = v === Et2 ? undefined : v;
|
|
3460
|
+
} else
|
|
3461
|
+
f?.uri !== undefined && (l = f.uri.length === 0 ? undefined : f.uri);
|
|
3462
|
+
}
|
|
3463
|
+
const d = n ? At2(n) : undefined;
|
|
3464
|
+
m === `
|
|
3465
|
+
` ? (l && (i += Ue("")), n && d && (i += He(d))) : $ === `
|
|
3466
|
+
` && (n && d && (i += He(n)), l && (i += Ue(l))), y2 += $.length, E = p, p = g.next();
|
|
3467
|
+
}
|
|
3468
|
+
return i;
|
|
3469
|
+
};
|
|
3470
|
+
function q2(e, r, s) {
|
|
3471
|
+
return String(e).normalize().replaceAll(`\r
|
|
3472
|
+
`, `
|
|
3473
|
+
`).split(`
|
|
3474
|
+
`).map((i) => It2(i, r, s)).join(`
|
|
3475
|
+
`);
|
|
3476
|
+
}
|
|
3477
|
+
var St2 = (e, r, s, i, n) => {
|
|
3478
|
+
let l = r, u = 0;
|
|
3479
|
+
for (let o = s;o < i; o++) {
|
|
3480
|
+
const a = e[o];
|
|
3481
|
+
if (l = l - a.length, u++, l <= n)
|
|
3482
|
+
break;
|
|
3483
|
+
}
|
|
3484
|
+
return { lineCount: l, removals: u };
|
|
3485
|
+
};
|
|
3486
|
+
var J = (e) => {
|
|
3487
|
+
const { cursor: r, options: s, style: i } = e, n = e.output ?? process.stdout, l = rt(n), u = e.columnPadding ?? 0, o = e.rowPadding ?? 4, a = l - u, c = nt(n), g = import_picocolors2.default.dim("..."), E = e.maxItems ?? Number.POSITIVE_INFINITY, p = Math.max(c - o, 0), y2 = Math.max(Math.min(E, p), 5);
|
|
3488
|
+
let $ = 0;
|
|
3489
|
+
r >= y2 - 3 && ($ = Math.max(Math.min(r - y2 + 3, s.length - y2), 0));
|
|
3490
|
+
let m = y2 < s.length && $ > 0, d = y2 < s.length && $ + y2 < s.length;
|
|
3491
|
+
const F = Math.min($ + y2, s.length), f = [];
|
|
3492
|
+
let v = 0;
|
|
3493
|
+
m && v++, d && v++;
|
|
3494
|
+
const I2 = $ + (m ? 1 : 0), B = F - (d ? 1 : 0);
|
|
3495
|
+
for (let A = I2;A < B; A++) {
|
|
3496
|
+
const C = q2(i(s[A], A === r), a, { hard: true, trim: false }).split(`
|
|
3497
|
+
`);
|
|
3498
|
+
f.push(C), v += C.length;
|
|
3499
|
+
}
|
|
3500
|
+
if (v > p) {
|
|
3501
|
+
let A = 0, C = 0, _2 = v;
|
|
3502
|
+
const D2 = r - I2, T2 = (W2, S2) => St2(f, _2, W2, S2, p);
|
|
3503
|
+
m ? ({ lineCount: _2, removals: A } = T2(0, D2), _2 > p && ({ lineCount: _2, removals: C } = T2(D2 + 1, f.length))) : ({ lineCount: _2, removals: C } = T2(D2 + 1, f.length), _2 > p && ({ lineCount: _2, removals: A } = T2(0, D2))), A > 0 && (m = true, f.splice(0, A)), C > 0 && (d = true, f.splice(f.length - C, C));
|
|
3504
|
+
}
|
|
3505
|
+
const b = [];
|
|
3506
|
+
m && b.push(g);
|
|
3507
|
+
for (const A of f)
|
|
3508
|
+
for (const C of A)
|
|
3509
|
+
b.push(C);
|
|
3510
|
+
return d && b.push(g), b;
|
|
3511
|
+
};
|
|
3512
|
+
var Mt2 = (e) => {
|
|
3513
|
+
const r = e.active ?? "Yes", s = e.inactive ?? "No";
|
|
3514
|
+
return new kt({ active: r, inactive: s, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue ?? true, render() {
|
|
3515
|
+
const i = `${import_picocolors2.default.gray(h)}
|
|
3516
|
+
${N2(this.state)} ${e.message}
|
|
3517
|
+
`, n = this.value ? r : s;
|
|
3518
|
+
switch (this.state) {
|
|
3519
|
+
case "submit":
|
|
3520
|
+
return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.dim(n)}`;
|
|
3521
|
+
case "cancel":
|
|
3522
|
+
return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(n))}
|
|
3523
|
+
${import_picocolors2.default.gray(h)}`;
|
|
3524
|
+
default:
|
|
3525
|
+
return `${i}${import_picocolors2.default.cyan(h)} ${this.value ? `${import_picocolors2.default.green(Y)} ${r}` : `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(r)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.green(Y)} ${s}`}
|
|
3526
|
+
${import_picocolors2.default.cyan(x2)}
|
|
3527
|
+
`;
|
|
3528
|
+
}
|
|
3529
|
+
} }).prompt();
|
|
3530
|
+
};
|
|
3531
|
+
var Ut = import_picocolors2.default.magenta;
|
|
3532
|
+
var Ye = { light: w2("─", "-"), heavy: w2("━", "="), block: w2("█", "#") };
|
|
3533
|
+
var oe = (e, r) => e.includes(`
|
|
3534
|
+
`) ? e.split(`
|
|
3535
|
+
`).map((s) => r(s)).join(`
|
|
3536
|
+
`) : r(e);
|
|
3537
|
+
var qt = (e) => {
|
|
3538
|
+
const r = (s, i) => {
|
|
3539
|
+
const n = s.label ?? String(s.value);
|
|
3540
|
+
switch (i) {
|
|
3541
|
+
case "disabled":
|
|
3542
|
+
return `${import_picocolors2.default.gray(K2)} ${oe(n, import_picocolors2.default.gray)}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
3543
|
+
case "selected":
|
|
3544
|
+
return `${oe(n, import_picocolors2.default.dim)}`;
|
|
3545
|
+
case "active":
|
|
3546
|
+
return `${import_picocolors2.default.green(Y)} ${n}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint})`)}` : ""}`;
|
|
3547
|
+
case "cancelled":
|
|
3548
|
+
return `${oe(n, (l) => import_picocolors2.default.strikethrough(import_picocolors2.default.dim(l)))}`;
|
|
3549
|
+
default:
|
|
3550
|
+
return `${import_picocolors2.default.dim(K2)} ${oe(n, import_picocolors2.default.dim)}`;
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
return new Wt({ options: e.options, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue, render() {
|
|
3554
|
+
const s = `${N2(this.state)} `, i = `${Ee(this.state)} `, n = Bt(e.output, e.message, i, s), l = `${import_picocolors2.default.gray(h)}
|
|
3555
|
+
${n}
|
|
3556
|
+
`;
|
|
3557
|
+
switch (this.state) {
|
|
3558
|
+
case "submit": {
|
|
3559
|
+
const u = `${import_picocolors2.default.gray(h)} `, o = Bt(e.output, r(this.options[this.cursor], "selected"), u);
|
|
3560
|
+
return `${l}${o}`;
|
|
3561
|
+
}
|
|
3562
|
+
case "cancel": {
|
|
3563
|
+
const u = `${import_picocolors2.default.gray(h)} `, o = Bt(e.output, r(this.options[this.cursor], "cancelled"), u);
|
|
3564
|
+
return `${l}${o}
|
|
3565
|
+
${import_picocolors2.default.gray(h)}`;
|
|
3566
|
+
}
|
|
3567
|
+
default: {
|
|
3568
|
+
const u = `${import_picocolors2.default.cyan(h)} `, o = l.split(`
|
|
3569
|
+
`).length;
|
|
3570
|
+
return `${l}${u}${J({ output: e.output, cursor: this.cursor, options: this.options, maxItems: e.maxItems, columnPadding: u.length, rowPadding: o + 2, style: (a, c) => r(a, a.disabled ? "disabled" : c ? "active" : "inactive") }).join(`
|
|
3571
|
+
${u}`)}
|
|
3572
|
+
${import_picocolors2.default.cyan(x2)}
|
|
3573
|
+
`;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
} }).prompt();
|
|
3577
|
+
};
|
|
3578
|
+
var ze = `${import_picocolors2.default.gray(h)} `;
|
|
3579
|
+
|
|
3580
|
+
// src/auth/antigravity/cli.ts
|
|
3581
|
+
async function promptAddAnotherAccount(currentCount) {
|
|
3582
|
+
if (!process.stdout.isTTY) {
|
|
3583
|
+
return false;
|
|
3584
|
+
}
|
|
3585
|
+
const result = await Mt2({
|
|
3586
|
+
message: `Add another Google account?
|
|
3587
|
+
Currently have ${currentCount} accounts (max 10)`
|
|
3588
|
+
});
|
|
3589
|
+
if (Ct(result)) {
|
|
3590
|
+
return false;
|
|
3591
|
+
}
|
|
3592
|
+
return result;
|
|
3593
|
+
}
|
|
3594
|
+
async function promptAccountTier() {
|
|
3595
|
+
if (!process.stdout.isTTY) {
|
|
3596
|
+
return "free";
|
|
3597
|
+
}
|
|
3598
|
+
const tier = await qt({
|
|
3599
|
+
message: "Select account tier",
|
|
3600
|
+
options: [
|
|
3601
|
+
{ value: "free", label: "Free" },
|
|
3602
|
+
{ value: "paid", label: "Paid" }
|
|
3603
|
+
]
|
|
3604
|
+
});
|
|
3605
|
+
if (Ct(tier)) {
|
|
3606
|
+
return "free";
|
|
3607
|
+
}
|
|
3608
|
+
return tier;
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
// node_modules/open/index.js
|
|
3612
|
+
import process8 from "node:process";
|
|
3613
|
+
import path2 from "node:path";
|
|
3614
|
+
import { fileURLToPath } from "node:url";
|
|
3615
|
+
import childProcess3 from "node:child_process";
|
|
3616
|
+
import fs6, { constants as fsConstants2 } from "node:fs/promises";
|
|
3617
|
+
|
|
3618
|
+
// node_modules/wsl-utils/index.js
|
|
3619
|
+
import { promisify as promisify2 } from "node:util";
|
|
3620
|
+
import childProcess2 from "node:child_process";
|
|
3621
|
+
import fs5, { constants as fsConstants } from "node:fs/promises";
|
|
3622
|
+
|
|
3623
|
+
// node_modules/is-wsl/index.js
|
|
3624
|
+
import process2 from "node:process";
|
|
3625
|
+
import os2 from "node:os";
|
|
3626
|
+
import fs4 from "node:fs";
|
|
3627
|
+
|
|
3628
|
+
// node_modules/is-inside-container/index.js
|
|
3629
|
+
import fs3 from "node:fs";
|
|
3630
|
+
|
|
3631
|
+
// node_modules/is-docker/index.js
|
|
3632
|
+
import fs2 from "node:fs";
|
|
3633
|
+
var isDockerCached;
|
|
3634
|
+
function hasDockerEnv() {
|
|
3635
|
+
try {
|
|
3636
|
+
fs2.statSync("/.dockerenv");
|
|
3637
|
+
return true;
|
|
3638
|
+
} catch {
|
|
3639
|
+
return false;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
function hasDockerCGroup() {
|
|
3643
|
+
try {
|
|
3644
|
+
return fs2.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
3645
|
+
} catch {
|
|
3646
|
+
return false;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
function isDocker() {
|
|
3650
|
+
if (isDockerCached === undefined) {
|
|
3651
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
3652
|
+
}
|
|
3653
|
+
return isDockerCached;
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
// node_modules/is-inside-container/index.js
|
|
3657
|
+
var cachedResult;
|
|
3658
|
+
var hasContainerEnv = () => {
|
|
3659
|
+
try {
|
|
3660
|
+
fs3.statSync("/run/.containerenv");
|
|
3661
|
+
return true;
|
|
3662
|
+
} catch {
|
|
3663
|
+
return false;
|
|
3664
|
+
}
|
|
3665
|
+
};
|
|
3666
|
+
function isInsideContainer() {
|
|
3667
|
+
if (cachedResult === undefined) {
|
|
3668
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
3669
|
+
}
|
|
3670
|
+
return cachedResult;
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
// node_modules/is-wsl/index.js
|
|
3674
|
+
var isWsl = () => {
|
|
3675
|
+
if (process2.platform !== "linux") {
|
|
3676
|
+
return false;
|
|
3677
|
+
}
|
|
3678
|
+
if (os2.release().toLowerCase().includes("microsoft")) {
|
|
3679
|
+
if (isInsideContainer()) {
|
|
3680
|
+
return false;
|
|
3681
|
+
}
|
|
3682
|
+
return true;
|
|
3683
|
+
}
|
|
3684
|
+
try {
|
|
3685
|
+
return fs4.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
|
|
3686
|
+
} catch {
|
|
3687
|
+
return false;
|
|
3688
|
+
}
|
|
3689
|
+
};
|
|
3690
|
+
var is_wsl_default = process2.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
3691
|
+
|
|
3692
|
+
// node_modules/powershell-utils/index.js
|
|
3693
|
+
import process3 from "node:process";
|
|
3694
|
+
import { Buffer } from "node:buffer";
|
|
3695
|
+
import { promisify } from "node:util";
|
|
3696
|
+
import childProcess from "node:child_process";
|
|
3697
|
+
var execFile = promisify(childProcess.execFile);
|
|
3698
|
+
var powerShellPath = () => `${process3.env.SYSTEMROOT || process3.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
3699
|
+
var executePowerShell = async (command, options = {}) => {
|
|
3700
|
+
const {
|
|
3701
|
+
powerShellPath: psPath,
|
|
3702
|
+
...execFileOptions
|
|
3703
|
+
} = options;
|
|
3704
|
+
const encodedCommand = executePowerShell.encodeCommand(command);
|
|
3705
|
+
return execFile(psPath ?? powerShellPath(), [
|
|
3706
|
+
...executePowerShell.argumentsPrefix,
|
|
3707
|
+
encodedCommand
|
|
3708
|
+
], {
|
|
3709
|
+
encoding: "utf8",
|
|
3710
|
+
...execFileOptions
|
|
3711
|
+
});
|
|
3712
|
+
};
|
|
3713
|
+
executePowerShell.argumentsPrefix = [
|
|
3714
|
+
"-NoProfile",
|
|
3715
|
+
"-NonInteractive",
|
|
3716
|
+
"-ExecutionPolicy",
|
|
3717
|
+
"Bypass",
|
|
3718
|
+
"-EncodedCommand"
|
|
3719
|
+
];
|
|
3720
|
+
executePowerShell.encodeCommand = (command) => Buffer.from(command, "utf16le").toString("base64");
|
|
3721
|
+
executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
3722
|
+
|
|
3723
|
+
// node_modules/wsl-utils/utilities.js
|
|
3724
|
+
function parseMountPointFromConfig(content) {
|
|
3725
|
+
for (const line of content.split(`
|
|
3726
|
+
`)) {
|
|
3727
|
+
if (/^\s*#/.test(line)) {
|
|
3728
|
+
continue;
|
|
3729
|
+
}
|
|
3730
|
+
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
|
3731
|
+
if (!match) {
|
|
3732
|
+
continue;
|
|
3733
|
+
}
|
|
3734
|
+
return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
// node_modules/wsl-utils/index.js
|
|
3739
|
+
var execFile2 = promisify2(childProcess2.execFile);
|
|
3740
|
+
var wslDrivesMountPoint = (() => {
|
|
3741
|
+
const defaultMountPoint = "/mnt/";
|
|
3742
|
+
let mountPoint;
|
|
3743
|
+
return async function() {
|
|
3744
|
+
if (mountPoint) {
|
|
3745
|
+
return mountPoint;
|
|
3746
|
+
}
|
|
3747
|
+
const configFilePath = "/etc/wsl.conf";
|
|
3748
|
+
let isConfigFileExists = false;
|
|
3749
|
+
try {
|
|
3750
|
+
await fs5.access(configFilePath, fsConstants.F_OK);
|
|
3751
|
+
isConfigFileExists = true;
|
|
3752
|
+
} catch {}
|
|
3753
|
+
if (!isConfigFileExists) {
|
|
3754
|
+
return defaultMountPoint;
|
|
3755
|
+
}
|
|
3756
|
+
const configContent = await fs5.readFile(configFilePath, { encoding: "utf8" });
|
|
3757
|
+
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
|
3758
|
+
if (parsedMountPoint === undefined) {
|
|
3759
|
+
return defaultMountPoint;
|
|
3760
|
+
}
|
|
3761
|
+
mountPoint = parsedMountPoint;
|
|
3762
|
+
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
3763
|
+
return mountPoint;
|
|
3764
|
+
};
|
|
3765
|
+
})();
|
|
3766
|
+
var powerShellPathFromWsl = async () => {
|
|
3767
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
3768
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
3769
|
+
};
|
|
3770
|
+
var powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
|
|
3771
|
+
var canAccessPowerShellPromise;
|
|
3772
|
+
var canAccessPowerShell = async () => {
|
|
3773
|
+
canAccessPowerShellPromise ??= (async () => {
|
|
3774
|
+
try {
|
|
3775
|
+
const psPath = await powerShellPath2();
|
|
3776
|
+
await fs5.access(psPath, fsConstants.X_OK);
|
|
3777
|
+
return true;
|
|
3778
|
+
} catch {
|
|
3779
|
+
return false;
|
|
3780
|
+
}
|
|
3781
|
+
})();
|
|
3782
|
+
return canAccessPowerShellPromise;
|
|
3783
|
+
};
|
|
3784
|
+
var wslDefaultBrowser = async () => {
|
|
3785
|
+
const psPath = await powerShellPath2();
|
|
3786
|
+
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
3787
|
+
const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
|
|
3788
|
+
return stdout.trim();
|
|
3789
|
+
};
|
|
3790
|
+
var convertWslPathToWindows = async (path2) => {
|
|
3791
|
+
if (/^[a-z]+:\/\//i.test(path2)) {
|
|
3792
|
+
return path2;
|
|
3793
|
+
}
|
|
3794
|
+
try {
|
|
3795
|
+
const { stdout } = await execFile2("wslpath", ["-aw", path2], { encoding: "utf8" });
|
|
3796
|
+
return stdout.trim();
|
|
3797
|
+
} catch {
|
|
3798
|
+
return path2;
|
|
3799
|
+
}
|
|
3800
|
+
};
|
|
3801
|
+
|
|
3802
|
+
// node_modules/define-lazy-prop/index.js
|
|
3803
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
3804
|
+
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
3805
|
+
Object.defineProperty(object, propertyName, {
|
|
3806
|
+
configurable: true,
|
|
3807
|
+
enumerable: true,
|
|
3808
|
+
get() {
|
|
3809
|
+
const result = valueGetter();
|
|
3810
|
+
define(result);
|
|
3811
|
+
return result;
|
|
3812
|
+
},
|
|
3813
|
+
set(value) {
|
|
3814
|
+
define(value);
|
|
3815
|
+
}
|
|
3816
|
+
});
|
|
3817
|
+
return object;
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
// node_modules/default-browser/index.js
|
|
3821
|
+
import { promisify as promisify6 } from "node:util";
|
|
3822
|
+
import process6 from "node:process";
|
|
3823
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
3824
|
+
|
|
3825
|
+
// node_modules/default-browser-id/index.js
|
|
3826
|
+
import { promisify as promisify3 } from "node:util";
|
|
3827
|
+
import process4 from "node:process";
|
|
3828
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
3829
|
+
var execFileAsync = promisify3(execFile3);
|
|
3830
|
+
async function defaultBrowserId() {
|
|
3831
|
+
if (process4.platform !== "darwin") {
|
|
3832
|
+
throw new Error("macOS only");
|
|
3833
|
+
}
|
|
3834
|
+
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
3835
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
3836
|
+
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
3837
|
+
if (browserId === "com.apple.safari") {
|
|
3838
|
+
return "com.apple.Safari";
|
|
3839
|
+
}
|
|
3840
|
+
return browserId;
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3843
|
+
// node_modules/run-applescript/index.js
|
|
3844
|
+
import process5 from "node:process";
|
|
3845
|
+
import { promisify as promisify4 } from "node:util";
|
|
3846
|
+
import { execFile as execFile4, execFileSync } from "node:child_process";
|
|
3847
|
+
var execFileAsync2 = promisify4(execFile4);
|
|
3848
|
+
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
3849
|
+
if (process5.platform !== "darwin") {
|
|
3850
|
+
throw new Error("macOS only");
|
|
3851
|
+
}
|
|
3852
|
+
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
3853
|
+
const execOptions = {};
|
|
3854
|
+
if (signal) {
|
|
3855
|
+
execOptions.signal = signal;
|
|
3856
|
+
}
|
|
3857
|
+
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
|
|
3858
|
+
return stdout.trim();
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
// node_modules/bundle-name/index.js
|
|
3862
|
+
async function bundleName(bundleId) {
|
|
3863
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
3864
|
+
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
3865
|
+
}
|
|
3866
|
+
|
|
3867
|
+
// node_modules/default-browser/windows.js
|
|
3868
|
+
import { promisify as promisify5 } from "node:util";
|
|
3869
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
3870
|
+
var execFileAsync3 = promisify5(execFile5);
|
|
3871
|
+
var windowsBrowserProgIds = {
|
|
3872
|
+
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
3873
|
+
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
3874
|
+
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
3875
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
3876
|
+
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
3877
|
+
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
3878
|
+
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
3879
|
+
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
3880
|
+
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
3881
|
+
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
3882
|
+
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
3883
|
+
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
3884
|
+
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
3885
|
+
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
3886
|
+
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
3887
|
+
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
3888
|
+
};
|
|
3889
|
+
var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
3890
|
+
|
|
3891
|
+
class UnknownBrowserError extends Error {
|
|
3892
|
+
}
|
|
3893
|
+
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
3894
|
+
const { stdout } = await _execFileAsync("reg", [
|
|
3895
|
+
"QUERY",
|
|
3896
|
+
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
3897
|
+
"/v",
|
|
3898
|
+
"ProgId"
|
|
3899
|
+
]);
|
|
3900
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
3901
|
+
if (!match) {
|
|
3902
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
3903
|
+
}
|
|
3904
|
+
const { id } = match.groups;
|
|
3905
|
+
const browser = windowsBrowserProgIds[id];
|
|
3906
|
+
if (!browser) {
|
|
3907
|
+
throw new UnknownBrowserError(`Unknown browser ID: ${id}`);
|
|
3908
|
+
}
|
|
3909
|
+
return browser;
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
// node_modules/default-browser/index.js
|
|
3913
|
+
var execFileAsync4 = promisify6(execFile6);
|
|
3914
|
+
var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x3) => x3.toUpperCase());
|
|
3915
|
+
async function defaultBrowser2() {
|
|
3916
|
+
if (process6.platform === "darwin") {
|
|
3917
|
+
const id = await defaultBrowserId();
|
|
3918
|
+
const name = await bundleName(id);
|
|
3919
|
+
return { name, id };
|
|
3920
|
+
}
|
|
3921
|
+
if (process6.platform === "linux") {
|
|
3922
|
+
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
3923
|
+
const id = stdout.trim();
|
|
3924
|
+
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
3925
|
+
return { name, id };
|
|
3926
|
+
}
|
|
3927
|
+
if (process6.platform === "win32") {
|
|
3928
|
+
return defaultBrowser();
|
|
3929
|
+
}
|
|
3930
|
+
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3933
|
+
// node_modules/is-in-ssh/index.js
|
|
3934
|
+
import process7 from "node:process";
|
|
3935
|
+
var isInSsh = Boolean(process7.env.SSH_CONNECTION || process7.env.SSH_CLIENT || process7.env.SSH_TTY);
|
|
3936
|
+
var is_in_ssh_default = isInSsh;
|
|
3937
|
+
|
|
3938
|
+
// node_modules/open/index.js
|
|
3939
|
+
var fallbackAttemptSymbol = Symbol("fallbackAttempt");
|
|
3940
|
+
var __dirname2 = import.meta.url ? path2.dirname(fileURLToPath(import.meta.url)) : "";
|
|
3941
|
+
var localXdgOpenPath = path2.join(__dirname2, "xdg-open");
|
|
3942
|
+
var { platform, arch } = process8;
|
|
3943
|
+
var tryEachApp = async (apps, opener) => {
|
|
3944
|
+
if (apps.length === 0) {
|
|
3945
|
+
return;
|
|
3946
|
+
}
|
|
3947
|
+
const errors = [];
|
|
3948
|
+
for (const app of apps) {
|
|
3949
|
+
try {
|
|
3950
|
+
return await opener(app);
|
|
3951
|
+
} catch (error) {
|
|
3952
|
+
errors.push(error);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
throw new AggregateError(errors, "Failed to open in all supported apps");
|
|
3956
|
+
};
|
|
3957
|
+
var baseOpen = async (options) => {
|
|
3958
|
+
options = {
|
|
3959
|
+
wait: false,
|
|
3960
|
+
background: false,
|
|
3961
|
+
newInstance: false,
|
|
3962
|
+
allowNonzeroExitCode: false,
|
|
3963
|
+
...options
|
|
3964
|
+
};
|
|
3965
|
+
const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
|
|
3966
|
+
delete options[fallbackAttemptSymbol];
|
|
3967
|
+
if (Array.isArray(options.app)) {
|
|
3968
|
+
return tryEachApp(options.app, (singleApp) => baseOpen({
|
|
3969
|
+
...options,
|
|
3970
|
+
app: singleApp,
|
|
3971
|
+
[fallbackAttemptSymbol]: true
|
|
3972
|
+
}));
|
|
3973
|
+
}
|
|
3974
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
3975
|
+
appArguments = [...appArguments];
|
|
3976
|
+
if (Array.isArray(app)) {
|
|
3977
|
+
return tryEachApp(app, (appName) => baseOpen({
|
|
3978
|
+
...options,
|
|
3979
|
+
app: {
|
|
3980
|
+
name: appName,
|
|
3981
|
+
arguments: appArguments
|
|
3982
|
+
},
|
|
3983
|
+
[fallbackAttemptSymbol]: true
|
|
3984
|
+
}));
|
|
3985
|
+
}
|
|
3986
|
+
if (app === "browser" || app === "browserPrivate") {
|
|
3987
|
+
const ids = {
|
|
3988
|
+
"com.google.chrome": "chrome",
|
|
3989
|
+
"google-chrome.desktop": "chrome",
|
|
3990
|
+
"com.brave.browser": "brave",
|
|
3991
|
+
"org.mozilla.firefox": "firefox",
|
|
3992
|
+
"firefox.desktop": "firefox",
|
|
3993
|
+
"com.microsoft.msedge": "edge",
|
|
3994
|
+
"com.microsoft.edge": "edge",
|
|
3995
|
+
"com.microsoft.edgemac": "edge",
|
|
3996
|
+
"microsoft-edge.desktop": "edge",
|
|
3997
|
+
"com.apple.safari": "safari"
|
|
3998
|
+
};
|
|
3999
|
+
const flags = {
|
|
4000
|
+
chrome: "--incognito",
|
|
4001
|
+
brave: "--incognito",
|
|
4002
|
+
firefox: "--private-window",
|
|
4003
|
+
edge: "--inPrivate"
|
|
4004
|
+
};
|
|
4005
|
+
let browser;
|
|
4006
|
+
if (is_wsl_default) {
|
|
4007
|
+
const progId = await wslDefaultBrowser();
|
|
4008
|
+
const browserInfo = _windowsBrowserProgIdMap.get(progId);
|
|
4009
|
+
browser = browserInfo ?? {};
|
|
4010
|
+
} else {
|
|
4011
|
+
browser = await defaultBrowser2();
|
|
4012
|
+
}
|
|
4013
|
+
if (browser.id in ids) {
|
|
4014
|
+
const browserName = ids[browser.id.toLowerCase()];
|
|
4015
|
+
if (app === "browserPrivate") {
|
|
4016
|
+
if (browserName === "safari") {
|
|
4017
|
+
throw new Error("Safari doesn't support opening in private mode via command line");
|
|
4018
|
+
}
|
|
4019
|
+
appArguments.push(flags[browserName]);
|
|
4020
|
+
}
|
|
4021
|
+
return baseOpen({
|
|
4022
|
+
...options,
|
|
4023
|
+
app: {
|
|
4024
|
+
name: apps[browserName],
|
|
4025
|
+
arguments: appArguments
|
|
4026
|
+
}
|
|
4027
|
+
});
|
|
4028
|
+
}
|
|
4029
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
4030
|
+
}
|
|
4031
|
+
let command;
|
|
4032
|
+
const cliArguments = [];
|
|
4033
|
+
const childProcessOptions = {};
|
|
4034
|
+
let shouldUseWindowsInWsl = false;
|
|
4035
|
+
if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
|
|
4036
|
+
shouldUseWindowsInWsl = await canAccessPowerShell();
|
|
4037
|
+
}
|
|
4038
|
+
if (platform === "darwin") {
|
|
4039
|
+
command = "open";
|
|
4040
|
+
if (options.wait) {
|
|
4041
|
+
cliArguments.push("--wait-apps");
|
|
4042
|
+
}
|
|
4043
|
+
if (options.background) {
|
|
4044
|
+
cliArguments.push("--background");
|
|
4045
|
+
}
|
|
4046
|
+
if (options.newInstance) {
|
|
4047
|
+
cliArguments.push("--new");
|
|
4048
|
+
}
|
|
4049
|
+
if (app) {
|
|
4050
|
+
cliArguments.push("-a", app);
|
|
4051
|
+
}
|
|
4052
|
+
} else if (platform === "win32" || shouldUseWindowsInWsl) {
|
|
4053
|
+
command = await powerShellPath2();
|
|
4054
|
+
cliArguments.push(...executePowerShell.argumentsPrefix);
|
|
4055
|
+
if (!is_wsl_default) {
|
|
4056
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
4057
|
+
}
|
|
4058
|
+
if (is_wsl_default && options.target) {
|
|
4059
|
+
options.target = await convertWslPathToWindows(options.target);
|
|
4060
|
+
}
|
|
4061
|
+
const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
|
|
4062
|
+
if (options.wait) {
|
|
4063
|
+
encodedArguments.push("-Wait");
|
|
4064
|
+
}
|
|
4065
|
+
if (app) {
|
|
4066
|
+
encodedArguments.push(executePowerShell.escapeArgument(app));
|
|
4067
|
+
if (options.target) {
|
|
4068
|
+
appArguments.push(options.target);
|
|
4069
|
+
}
|
|
4070
|
+
} else if (options.target) {
|
|
4071
|
+
encodedArguments.push(executePowerShell.escapeArgument(options.target));
|
|
4072
|
+
}
|
|
4073
|
+
if (appArguments.length > 0) {
|
|
4074
|
+
appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
|
|
4075
|
+
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
4076
|
+
}
|
|
4077
|
+
options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
|
|
4078
|
+
if (!options.wait) {
|
|
4079
|
+
childProcessOptions.stdio = "ignore";
|
|
4080
|
+
}
|
|
4081
|
+
} else {
|
|
4082
|
+
if (app) {
|
|
4083
|
+
command = app;
|
|
4084
|
+
} else {
|
|
4085
|
+
const isBundled = !__dirname2 || __dirname2 === "/";
|
|
4086
|
+
let exeLocalXdgOpen = false;
|
|
4087
|
+
try {
|
|
4088
|
+
await fs6.access(localXdgOpenPath, fsConstants2.X_OK);
|
|
4089
|
+
exeLocalXdgOpen = true;
|
|
4090
|
+
} catch {}
|
|
4091
|
+
const useSystemXdgOpen = process8.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
4092
|
+
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
4093
|
+
}
|
|
4094
|
+
if (appArguments.length > 0) {
|
|
4095
|
+
cliArguments.push(...appArguments);
|
|
4096
|
+
}
|
|
4097
|
+
if (!options.wait) {
|
|
4098
|
+
childProcessOptions.stdio = "ignore";
|
|
4099
|
+
childProcessOptions.detached = true;
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
if (platform === "darwin" && appArguments.length > 0) {
|
|
4103
|
+
cliArguments.push("--args", ...appArguments);
|
|
4104
|
+
}
|
|
4105
|
+
if (options.target) {
|
|
4106
|
+
cliArguments.push(options.target);
|
|
4107
|
+
}
|
|
4108
|
+
const subprocess = childProcess3.spawn(command, cliArguments, childProcessOptions);
|
|
4109
|
+
if (options.wait) {
|
|
4110
|
+
return new Promise((resolve, reject) => {
|
|
4111
|
+
subprocess.once("error", reject);
|
|
4112
|
+
subprocess.once("close", (exitCode) => {
|
|
4113
|
+
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
4114
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
4115
|
+
return;
|
|
4116
|
+
}
|
|
4117
|
+
resolve(subprocess);
|
|
4118
|
+
});
|
|
4119
|
+
});
|
|
4120
|
+
}
|
|
4121
|
+
if (isFallbackAttempt) {
|
|
4122
|
+
return new Promise((resolve, reject) => {
|
|
4123
|
+
subprocess.once("error", reject);
|
|
4124
|
+
subprocess.once("spawn", () => {
|
|
4125
|
+
subprocess.once("close", (exitCode) => {
|
|
4126
|
+
subprocess.off("error", reject);
|
|
4127
|
+
if (exitCode !== 0) {
|
|
4128
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
4129
|
+
return;
|
|
4130
|
+
}
|
|
4131
|
+
subprocess.unref();
|
|
4132
|
+
resolve(subprocess);
|
|
4133
|
+
});
|
|
4134
|
+
});
|
|
4135
|
+
});
|
|
4136
|
+
}
|
|
4137
|
+
subprocess.unref();
|
|
4138
|
+
return new Promise((resolve, reject) => {
|
|
4139
|
+
subprocess.once("error", reject);
|
|
4140
|
+
subprocess.once("spawn", () => {
|
|
4141
|
+
subprocess.off("error", reject);
|
|
4142
|
+
resolve(subprocess);
|
|
4143
|
+
});
|
|
4144
|
+
});
|
|
4145
|
+
};
|
|
4146
|
+
var open = (target, options) => {
|
|
4147
|
+
if (typeof target !== "string") {
|
|
4148
|
+
throw new TypeError("Expected a `target`");
|
|
4149
|
+
}
|
|
4150
|
+
return baseOpen({
|
|
4151
|
+
...options,
|
|
4152
|
+
target
|
|
4153
|
+
});
|
|
4154
|
+
};
|
|
4155
|
+
function detectArchBinary(binary) {
|
|
4156
|
+
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
4157
|
+
return binary;
|
|
4158
|
+
}
|
|
4159
|
+
const { [arch]: archBinary } = binary;
|
|
4160
|
+
if (!archBinary) {
|
|
4161
|
+
throw new Error(`${arch} is not supported`);
|
|
4162
|
+
}
|
|
4163
|
+
return archBinary;
|
|
4164
|
+
}
|
|
4165
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
|
|
4166
|
+
if (wsl && is_wsl_default) {
|
|
4167
|
+
return detectArchBinary(wsl);
|
|
4168
|
+
}
|
|
4169
|
+
if (!platformBinary) {
|
|
4170
|
+
throw new Error(`${platform} is not supported`);
|
|
4171
|
+
}
|
|
4172
|
+
return detectArchBinary(platformBinary);
|
|
4173
|
+
}
|
|
4174
|
+
var apps = {
|
|
4175
|
+
browser: "browser",
|
|
4176
|
+
browserPrivate: "browserPrivate"
|
|
4177
|
+
};
|
|
4178
|
+
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
4179
|
+
darwin: "google chrome",
|
|
4180
|
+
win32: "chrome",
|
|
4181
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
|
|
4182
|
+
}, {
|
|
4183
|
+
wsl: {
|
|
4184
|
+
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
4185
|
+
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
4186
|
+
}
|
|
4187
|
+
}));
|
|
4188
|
+
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
4189
|
+
darwin: "brave browser",
|
|
4190
|
+
win32: "brave",
|
|
4191
|
+
linux: ["brave-browser", "brave"]
|
|
4192
|
+
}, {
|
|
4193
|
+
wsl: {
|
|
4194
|
+
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
4195
|
+
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
4196
|
+
}
|
|
4197
|
+
}));
|
|
4198
|
+
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
4199
|
+
darwin: "firefox",
|
|
4200
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
4201
|
+
linux: "firefox"
|
|
4202
|
+
}, {
|
|
4203
|
+
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
4204
|
+
}));
|
|
4205
|
+
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
4206
|
+
darwin: "microsoft edge",
|
|
4207
|
+
win32: "msedge",
|
|
4208
|
+
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
4209
|
+
}, {
|
|
4210
|
+
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
4211
|
+
}));
|
|
4212
|
+
defineLazyProperty(apps, "safari", () => detectPlatformBinary({
|
|
4213
|
+
darwin: "Safari"
|
|
4214
|
+
}));
|
|
4215
|
+
var open_default = open;
|
|
4216
|
+
|
|
4217
|
+
// src/auth/antigravity/browser.ts
|
|
4218
|
+
function debugLog5(message) {
|
|
4219
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4220
|
+
console.log(`[antigravity-browser] ${message}`);
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
async function openBrowserURL(url) {
|
|
4224
|
+
debugLog5(`Opening browser: ${url}`);
|
|
4225
|
+
try {
|
|
4226
|
+
await open_default(url);
|
|
4227
|
+
debugLog5("Browser opened successfully");
|
|
4228
|
+
return true;
|
|
4229
|
+
} catch (error) {
|
|
4230
|
+
debugLog5(`Failed to open browser: ${error instanceof Error ? error.message : String(error)}`);
|
|
4231
|
+
return false;
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
// src/auth/antigravity/plugin.ts
|
|
4236
|
+
var GOOGLE_PROVIDER_ID = "google";
|
|
4237
|
+
var MAX_ACCOUNTS = 10;
|
|
4238
|
+
function isOAuthAuth(auth) {
|
|
4239
|
+
return auth.type === "oauth";
|
|
4240
|
+
}
|
|
4241
|
+
async function createGoogleAntigravityAuthPlugin({
|
|
4242
|
+
client
|
|
4243
|
+
}) {
|
|
4244
|
+
let cachedClientId = ANTIGRAVITY_CLIENT_ID;
|
|
4245
|
+
let cachedClientSecret = ANTIGRAVITY_CLIENT_SECRET;
|
|
4246
|
+
const authHook = {
|
|
4247
|
+
provider: GOOGLE_PROVIDER_ID,
|
|
4248
|
+
loader: async (auth, provider) => {
|
|
4249
|
+
const currentAuth = await auth();
|
|
4250
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4251
|
+
console.log("[antigravity-plugin] loader called");
|
|
4252
|
+
console.log("[antigravity-plugin] auth type:", currentAuth?.type);
|
|
4253
|
+
console.log("[antigravity-plugin] auth keys:", Object.keys(currentAuth || {}));
|
|
4254
|
+
}
|
|
4255
|
+
if (!isOAuthAuth(currentAuth)) {
|
|
4256
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4257
|
+
console.log("[antigravity-plugin] NOT OAuth auth, returning empty");
|
|
4258
|
+
}
|
|
4259
|
+
return {};
|
|
4260
|
+
}
|
|
4261
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4262
|
+
console.log("[antigravity-plugin] OAuth auth detected, creating custom fetch");
|
|
4263
|
+
}
|
|
4264
|
+
let accountManager = null;
|
|
4265
|
+
try {
|
|
4266
|
+
const storedAccounts = await loadAccounts();
|
|
4267
|
+
if (storedAccounts) {
|
|
4268
|
+
accountManager = new AccountManager(currentAuth, storedAccounts);
|
|
4269
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4270
|
+
console.log(`[antigravity-plugin] Loaded ${accountManager.getAccountCount()} accounts from storage`);
|
|
4271
|
+
}
|
|
4272
|
+
} else if (currentAuth.refresh.includes("|||")) {
|
|
4273
|
+
const tokens = currentAuth.refresh.split("|||");
|
|
4274
|
+
const firstToken = tokens[0];
|
|
4275
|
+
accountManager = new AccountManager({ refresh: firstToken, access: currentAuth.access || "", expires: currentAuth.expires || 0 }, null);
|
|
4276
|
+
for (let i = 1;i < tokens.length; i++) {
|
|
4277
|
+
const parts = parseStoredToken(tokens[i]);
|
|
4278
|
+
accountManager.addAccount(parts);
|
|
4279
|
+
}
|
|
4280
|
+
await accountManager.save();
|
|
4281
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4282
|
+
console.log("[antigravity-plugin] Migrated multi-account auth to storage");
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
} catch (error) {
|
|
4286
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4287
|
+
console.error(`[antigravity-plugin] Failed to load accounts: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
cachedClientId = provider.options?.clientId || ANTIGRAVITY_CLIENT_ID;
|
|
4291
|
+
cachedClientSecret = provider.options?.clientSecret || ANTIGRAVITY_CLIENT_SECRET;
|
|
4292
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1" && (cachedClientId !== ANTIGRAVITY_CLIENT_ID || cachedClientSecret !== ANTIGRAVITY_CLIENT_SECRET)) {
|
|
4293
|
+
console.log("[antigravity-plugin] Using custom credentials from provider.options");
|
|
4294
|
+
}
|
|
4295
|
+
const authClient = {
|
|
4296
|
+
set: async (providerId, authData) => {
|
|
4297
|
+
await client.auth.set({
|
|
4298
|
+
body: {
|
|
4299
|
+
type: "oauth",
|
|
4300
|
+
access: authData.access || "",
|
|
4301
|
+
refresh: authData.refresh || "",
|
|
4302
|
+
expires: authData.expires || 0
|
|
4303
|
+
},
|
|
4304
|
+
path: { id: providerId }
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
const getAuth = async () => {
|
|
4309
|
+
const authState = await auth();
|
|
4310
|
+
if (isOAuthAuth(authState)) {
|
|
4311
|
+
return {
|
|
4312
|
+
access: authState.access,
|
|
4313
|
+
refresh: authState.refresh,
|
|
4314
|
+
expires: authState.expires
|
|
4315
|
+
};
|
|
4316
|
+
}
|
|
4317
|
+
return {};
|
|
4318
|
+
};
|
|
4319
|
+
const antigravityFetch = createAntigravityFetch(getAuth, authClient, GOOGLE_PROVIDER_ID, cachedClientId, cachedClientSecret);
|
|
4320
|
+
return {
|
|
4321
|
+
fetch: antigravityFetch,
|
|
4322
|
+
apiKey: "antigravity-oauth",
|
|
4323
|
+
accountManager
|
|
4324
|
+
};
|
|
4325
|
+
},
|
|
4326
|
+
methods: [
|
|
4327
|
+
{
|
|
4328
|
+
type: "oauth",
|
|
4329
|
+
label: "OAuth with Google (Antigravity)",
|
|
4330
|
+
authorize: async () => {
|
|
4331
|
+
const serverHandle = startCallbackServer();
|
|
4332
|
+
const { url, state: expectedState } = await buildAuthURL(undefined, cachedClientId, serverHandle.port);
|
|
4333
|
+
const browserOpened = await openBrowserURL(url);
|
|
4334
|
+
return {
|
|
4335
|
+
url,
|
|
4336
|
+
instructions: browserOpened ? "Opening browser for sign-in. We'll automatically detect when you're done." : "Please open the URL above in your browser to sign in.",
|
|
4337
|
+
method: "auto",
|
|
4338
|
+
callback: async () => {
|
|
4339
|
+
try {
|
|
4340
|
+
const result = await serverHandle.waitForCallback();
|
|
4341
|
+
if (result.error) {
|
|
4342
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4343
|
+
console.error(`[antigravity-plugin] OAuth error: ${result.error}`);
|
|
4344
|
+
}
|
|
4345
|
+
return { type: "failed" };
|
|
4346
|
+
}
|
|
4347
|
+
if (!result.code) {
|
|
4348
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4349
|
+
console.error("[antigravity-plugin] No authorization code received");
|
|
4350
|
+
}
|
|
4351
|
+
return { type: "failed" };
|
|
4352
|
+
}
|
|
4353
|
+
if (result.state !== expectedState) {
|
|
4354
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4355
|
+
console.error("[antigravity-plugin] State mismatch - possible CSRF attack");
|
|
4356
|
+
}
|
|
4357
|
+
return { type: "failed" };
|
|
4358
|
+
}
|
|
4359
|
+
const redirectUri = `http://localhost:${serverHandle.port}/oauth-callback`;
|
|
4360
|
+
const tokens = await exchangeCode(result.code, redirectUri, cachedClientId, cachedClientSecret);
|
|
4361
|
+
if (!tokens.refresh_token) {
|
|
4362
|
+
serverHandle.close();
|
|
4363
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4364
|
+
console.error("[antigravity-plugin] OAuth response missing refresh_token");
|
|
4365
|
+
}
|
|
4366
|
+
return { type: "failed" };
|
|
4367
|
+
}
|
|
4368
|
+
let email;
|
|
4369
|
+
try {
|
|
4370
|
+
const userInfo = await fetchUserInfo(tokens.access_token);
|
|
4371
|
+
email = userInfo.email;
|
|
4372
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4373
|
+
console.log(`[antigravity-plugin] Authenticated as: ${email}`);
|
|
4374
|
+
}
|
|
4375
|
+
} catch {}
|
|
4376
|
+
const projectContext = await fetchProjectContext(tokens.access_token);
|
|
4377
|
+
const projectId = projectContext.cloudaicompanionProject || "";
|
|
4378
|
+
const tier = await promptAccountTier();
|
|
4379
|
+
const expires = Date.now() + tokens.expires_in * 1000;
|
|
4380
|
+
const accounts = [{
|
|
4381
|
+
parts: {
|
|
4382
|
+
refreshToken: tokens.refresh_token,
|
|
4383
|
+
projectId,
|
|
4384
|
+
managedProjectId: projectContext.managedProjectId
|
|
4385
|
+
},
|
|
4386
|
+
access: tokens.access_token,
|
|
4387
|
+
expires,
|
|
4388
|
+
email,
|
|
4389
|
+
tier,
|
|
4390
|
+
projectId
|
|
4391
|
+
}];
|
|
4392
|
+
await client.tui.showToast({
|
|
4393
|
+
body: {
|
|
4394
|
+
message: `Account 1 authenticated${email ? ` (${email})` : ""}`,
|
|
4395
|
+
variant: "success"
|
|
4396
|
+
}
|
|
4397
|
+
});
|
|
4398
|
+
while (accounts.length < MAX_ACCOUNTS) {
|
|
4399
|
+
const addAnother = await promptAddAnotherAccount(accounts.length);
|
|
4400
|
+
if (!addAnother)
|
|
4401
|
+
break;
|
|
4402
|
+
const additionalServerHandle = startCallbackServer();
|
|
4403
|
+
const { url: additionalUrl, state: expectedAdditionalState } = await buildAuthURL(undefined, cachedClientId, additionalServerHandle.port);
|
|
4404
|
+
const additionalBrowserOpened = await openBrowserURL(additionalUrl);
|
|
4405
|
+
if (!additionalBrowserOpened) {
|
|
4406
|
+
await client.tui.showToast({
|
|
4407
|
+
body: {
|
|
4408
|
+
message: `Please open in browser: ${additionalUrl}`,
|
|
4409
|
+
variant: "warning"
|
|
4410
|
+
}
|
|
4411
|
+
});
|
|
4412
|
+
}
|
|
4413
|
+
try {
|
|
4414
|
+
const additionalResult = await additionalServerHandle.waitForCallback();
|
|
4415
|
+
if (additionalResult.error || !additionalResult.code) {
|
|
4416
|
+
additionalServerHandle.close();
|
|
4417
|
+
await client.tui.showToast({
|
|
4418
|
+
body: {
|
|
4419
|
+
message: "Skipping this account...",
|
|
4420
|
+
variant: "warning"
|
|
4421
|
+
}
|
|
4422
|
+
});
|
|
4423
|
+
continue;
|
|
4424
|
+
}
|
|
4425
|
+
if (additionalResult.state !== expectedAdditionalState) {
|
|
4426
|
+
additionalServerHandle.close();
|
|
4427
|
+
await client.tui.showToast({
|
|
4428
|
+
body: {
|
|
4429
|
+
message: "State mismatch, skipping...",
|
|
4430
|
+
variant: "warning"
|
|
4431
|
+
}
|
|
4432
|
+
});
|
|
4433
|
+
continue;
|
|
4434
|
+
}
|
|
4435
|
+
const additionalRedirectUri = `http://localhost:${additionalServerHandle.port}/oauth-callback`;
|
|
4436
|
+
const additionalTokens = await exchangeCode(additionalResult.code, additionalRedirectUri, cachedClientId, cachedClientSecret);
|
|
4437
|
+
if (!additionalTokens.refresh_token) {
|
|
4438
|
+
additionalServerHandle.close();
|
|
4439
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4440
|
+
console.error("[antigravity-plugin] Additional account OAuth response missing refresh_token");
|
|
4441
|
+
}
|
|
4442
|
+
await client.tui.showToast({
|
|
4443
|
+
body: {
|
|
4444
|
+
message: "Account missing refresh token, skipping...",
|
|
4445
|
+
variant: "warning"
|
|
4446
|
+
}
|
|
4447
|
+
});
|
|
4448
|
+
continue;
|
|
4449
|
+
}
|
|
4450
|
+
let additionalEmail;
|
|
4451
|
+
try {
|
|
4452
|
+
const additionalUserInfo = await fetchUserInfo(additionalTokens.access_token);
|
|
4453
|
+
additionalEmail = additionalUserInfo.email;
|
|
4454
|
+
} catch {}
|
|
4455
|
+
const additionalProjectContext = await fetchProjectContext(additionalTokens.access_token);
|
|
4456
|
+
const additionalProjectId = additionalProjectContext.cloudaicompanionProject || "";
|
|
4457
|
+
const additionalTier = await promptAccountTier();
|
|
4458
|
+
const additionalExpires = Date.now() + additionalTokens.expires_in * 1000;
|
|
4459
|
+
accounts.push({
|
|
4460
|
+
parts: {
|
|
4461
|
+
refreshToken: additionalTokens.refresh_token,
|
|
4462
|
+
projectId: additionalProjectId,
|
|
4463
|
+
managedProjectId: additionalProjectContext.managedProjectId
|
|
4464
|
+
},
|
|
4465
|
+
access: additionalTokens.access_token,
|
|
4466
|
+
expires: additionalExpires,
|
|
4467
|
+
email: additionalEmail,
|
|
4468
|
+
tier: additionalTier,
|
|
4469
|
+
projectId: additionalProjectId
|
|
4470
|
+
});
|
|
4471
|
+
additionalServerHandle.close();
|
|
4472
|
+
await client.tui.showToast({
|
|
4473
|
+
body: {
|
|
4474
|
+
message: `Account ${accounts.length} authenticated${additionalEmail ? ` (${additionalEmail})` : ""}`,
|
|
4475
|
+
variant: "success"
|
|
4476
|
+
}
|
|
4477
|
+
});
|
|
4478
|
+
} catch (error) {
|
|
4479
|
+
additionalServerHandle.close();
|
|
4480
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4481
|
+
console.error(`[antigravity-plugin] Additional account OAuth failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
4482
|
+
}
|
|
4483
|
+
await client.tui.showToast({
|
|
4484
|
+
body: {
|
|
4485
|
+
message: "Failed to authenticate additional account, skipping...",
|
|
4486
|
+
variant: "warning"
|
|
4487
|
+
}
|
|
4488
|
+
});
|
|
4489
|
+
continue;
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
const firstAccount = accounts[0];
|
|
4493
|
+
try {
|
|
4494
|
+
const accountManager = new AccountManager({
|
|
4495
|
+
refresh: formatTokenForStorage(firstAccount.parts.refreshToken, firstAccount.projectId, firstAccount.parts.managedProjectId),
|
|
4496
|
+
access: firstAccount.access,
|
|
4497
|
+
expires: firstAccount.expires
|
|
4498
|
+
}, null);
|
|
4499
|
+
for (let i = 1;i < accounts.length; i++) {
|
|
4500
|
+
const acc = accounts[i];
|
|
4501
|
+
accountManager.addAccount(acc.parts, acc.access, acc.expires, acc.email, acc.tier);
|
|
4502
|
+
}
|
|
4503
|
+
const currentAccount = accountManager.getCurrentAccount();
|
|
4504
|
+
if (currentAccount) {
|
|
4505
|
+
currentAccount.email = firstAccount.email;
|
|
4506
|
+
currentAccount.tier = firstAccount.tier;
|
|
4507
|
+
}
|
|
4508
|
+
await accountManager.save();
|
|
4509
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4510
|
+
console.log(`[antigravity-plugin] Saved ${accounts.length} accounts to storage`);
|
|
4511
|
+
}
|
|
4512
|
+
} catch (error) {
|
|
4513
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4514
|
+
console.error(`[antigravity-plugin] Failed to save accounts: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
const allRefreshTokens = accounts.map((acc) => formatTokenForStorage(acc.parts.refreshToken, acc.projectId, acc.parts.managedProjectId)).join("|||");
|
|
4518
|
+
return {
|
|
4519
|
+
type: "success",
|
|
4520
|
+
access: firstAccount.access,
|
|
4521
|
+
refresh: allRefreshTokens,
|
|
4522
|
+
expires: firstAccount.expires
|
|
4523
|
+
};
|
|
4524
|
+
} catch (error) {
|
|
4525
|
+
serverHandle.close();
|
|
4526
|
+
if (process.env.ANTIGRAVITY_DEBUG === "1") {
|
|
4527
|
+
console.error(`[antigravity-plugin] OAuth flow failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
4528
|
+
}
|
|
4529
|
+
return { type: "failed" };
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
};
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
]
|
|
4536
|
+
};
|
|
4537
|
+
return {
|
|
4538
|
+
auth: authHook
|
|
4539
|
+
};
|
|
4540
|
+
}
|
|
4541
|
+
var GoogleAntigravityAuthPlugin = createGoogleAntigravityAuthPlugin;
|
|
4542
|
+
export {
|
|
4543
|
+
wrapRequestBody,
|
|
4544
|
+
transformStreamingResponse,
|
|
4545
|
+
transformStreamingPayload,
|
|
4546
|
+
transformResponseThinking,
|
|
4547
|
+
transformResponse,
|
|
4548
|
+
transformRequest,
|
|
4549
|
+
transformCandidateThinking,
|
|
4550
|
+
transformAnthropicThinking,
|
|
4551
|
+
startCallbackServer,
|
|
4552
|
+
shouldIncludeThinking,
|
|
4553
|
+
setThoughtSignature,
|
|
4554
|
+
resolveThinkingConfig,
|
|
4555
|
+
refreshAccessToken,
|
|
4556
|
+
performOAuthFlow,
|
|
4557
|
+
parseStoredToken,
|
|
4558
|
+
parseErrorBody,
|
|
4559
|
+
normalizeToolsForGemini,
|
|
4560
|
+
normalizeToolResultsFromGemini,
|
|
4561
|
+
normalizeThinkingConfig,
|
|
4562
|
+
normalizeModelId,
|
|
4563
|
+
isTokenExpired,
|
|
4564
|
+
isThinkingCapableModel,
|
|
4565
|
+
isStreamingResponse,
|
|
4566
|
+
isStreamingRequest,
|
|
4567
|
+
isGenerativeLanguageRequest,
|
|
4568
|
+
invalidateProjectContextByRefreshToken,
|
|
4569
|
+
injectThoughtSignatureIntoFunctionCalls,
|
|
4570
|
+
injectSystemPrompt,
|
|
4571
|
+
hasOpenAIMessages,
|
|
4572
|
+
hasFunctionTools,
|
|
4573
|
+
getThoughtSignature,
|
|
4574
|
+
getOrCreateSessionId,
|
|
4575
|
+
getModelThinkingConfig,
|
|
4576
|
+
getDefaultEndpoint,
|
|
4577
|
+
generatePKCEChallenge,
|
|
4578
|
+
formatTokenForStorage,
|
|
4579
|
+
formatThinkingForOpenAI,
|
|
4580
|
+
filterUnsignedThinkingBlocks,
|
|
4581
|
+
fetchUserInfo,
|
|
4582
|
+
fetchProjectContext,
|
|
4583
|
+
extractUsageFromSsePayload,
|
|
4584
|
+
extractUsageFromHeaders,
|
|
4585
|
+
extractThinkingConfig,
|
|
4586
|
+
extractThinkingBlocks,
|
|
4587
|
+
extractSignatureFromSsePayload,
|
|
4588
|
+
extractRetryAfterMs,
|
|
4589
|
+
extractModelFromUrl,
|
|
4590
|
+
extractModelFromBody,
|
|
4591
|
+
extractFunctionDeclarations,
|
|
4592
|
+
extractActionFromUrl,
|
|
4593
|
+
exchangeCode,
|
|
4594
|
+
createGoogleAntigravityAuthPlugin,
|
|
4595
|
+
createAntigravityFetch,
|
|
4596
|
+
convertRequestBody,
|
|
4597
|
+
convertOpenAIToGemini,
|
|
4598
|
+
convertFunctionCallToToolCall,
|
|
4599
|
+
clearThoughtSignature,
|
|
4600
|
+
clearSessionId,
|
|
4601
|
+
clearProjectContextCache,
|
|
4602
|
+
clearFetchInstanceData,
|
|
4603
|
+
buildRequestHeaders,
|
|
4604
|
+
buildAuthURL,
|
|
4605
|
+
buildAntigravityUrl,
|
|
4606
|
+
budgetToLevel,
|
|
4607
|
+
applyThinkingConfigToRequest,
|
|
4608
|
+
alias2ModelName,
|
|
4609
|
+
addStreamingHeaders,
|
|
4610
|
+
SKIP_THOUGHT_SIGNATURE_VALIDATOR,
|
|
4611
|
+
REASONING_EFFORT_BUDGET_MAP,
|
|
4612
|
+
MODEL_FAMILIES,
|
|
4613
|
+
GoogleAntigravityAuthPlugin,
|
|
4614
|
+
GOOGLE_USERINFO_URL,
|
|
4615
|
+
GOOGLE_TOKEN_URL,
|
|
4616
|
+
GOOGLE_AUTH_URL,
|
|
4617
|
+
DEFAULT_THINKING_BUDGET,
|
|
4618
|
+
AntigravityTokenRefreshError,
|
|
4619
|
+
ANTIGRAVITY_TOKEN_REFRESH_BUFFER_MS,
|
|
4620
|
+
ANTIGRAVITY_SYSTEM_PROMPT,
|
|
4621
|
+
ANTIGRAVITY_SUPPORTED_MODELS,
|
|
4622
|
+
ANTIGRAVITY_SCOPES,
|
|
4623
|
+
ANTIGRAVITY_REDIRECT_URI,
|
|
4624
|
+
ANTIGRAVITY_MODEL_CONFIGS,
|
|
4625
|
+
ANTIGRAVITY_HEADERS,
|
|
4626
|
+
ANTIGRAVITY_ENDPOINT_FALLBACKS,
|
|
4627
|
+
ANTIGRAVITY_DEFAULT_PROJECT_ID,
|
|
4628
|
+
ANTIGRAVITY_CLIENT_SECRET,
|
|
4629
|
+
ANTIGRAVITY_CLIENT_ID,
|
|
4630
|
+
ANTIGRAVITY_CALLBACK_PORT,
|
|
4631
|
+
ANTIGRAVITY_API_VERSION
|
|
4632
|
+
};
|