Open History to see the last commit
1// @effect-diagnostics-next-line nodeBuiltinImport:off - Effect's symlink has no type argument, and Windows needs a junction to link without elevation.
2import * as NodeFSP from "node:fs/promises";
3
4import type { AntigravityAuthMethod, ProviderInstanceId } from "@t3tools/contracts";
5import * as HostProcess from "@t3tools/shared/HostProcess";
6import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
7import * as Crypto from "effect/Crypto";
8import * as Effect from "effect/Effect";
9import * as Hex from "effect/encoding/Hex";
10import * as FileSystem from "effect/FileSystem";
11import * as Path from "effect/Path";
12import type * as PlatformError from "effect/PlatformError";
13import * as Schema from "effect/Schema";
14import * as Stream from "effect/Stream";
15import * as ChildProcess from "effect/process/ChildProcess";
16import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17import * as AcpErrors from "effect-acp/errors";
18
19import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
20import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
21import {
22 antigravityUserSkillDirectories,
23 resolveAntigravityUserHome,
24} from "./Drivers/AntigravitySkills.ts";
25
26export const ANTIGRAVITY_AUTH_STDOUT_PREFIX =
27 "Open the following link to authenticate the ACP server: ";
28export const ANTIGRAVITY_AUTH_BROWSER_MARKER = "__T3_ANTIGRAVITY_AUTH_URL__";
29export const ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE =
30 "Sign in to Antigravity in Settings before you continue.";
31
32const maxAuthorizationUrlLength = 16_384;
33const maxBrowserHelperLineLength =
34 Math.max(ANTIGRAVITY_AUTH_BROWSER_MARKER.length, ANTIGRAVITY_AUTH_STDOUT_PREFIX.length) +
35 maxAuthorizationUrlLength +
36 2;
37const maxStdoutLineBytes = 16 * 1024 * 1024;
38const authPrefixBytes = new TextEncoder().encode(ANTIGRAVITY_AUTH_STDOUT_PREFIX);
39const decodeUrl = Schema.decodeUnknownEffect(Schema.URLFromString);
40const decodeBrowserHelperUrl = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String));
41const ProfileSettingsFile = Schema.Struct({
42 auth: Schema.Struct({ type: Schema.String }),
43 gcp: Schema.optional(
44 Schema.Struct({
45 project: Schema.optional(Schema.String),
46 location: Schema.optional(Schema.String),
47 }),
48 ),
49});
50const encodeProfileSettings = Schema.encodeSync(Schema.fromJsonString(ProfileSettingsFile));
51const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError);
52const isAcpTransportError = Schema.is(AcpErrors.AcpTransportError);
53
54// Python splits BROWSER on the platform path separator before it parses quotes.
55// EPIPE must still exit 0 so Python does not fall back to an OS browser after
56// cancellation.
57const browserHelperSource =
58 `process.stderr.on("error",()=>process.exit(0)).write(` +
59 `"${ANTIGRAVITY_AUTH_BROWSER_MARKER}"+JSON.stringify(process.argv[1])+"\\n",` +
60 `()=>process.exit(0))`;
61const browserPreflightUrl = "https://example.invalid/t3-antigravity-browser-preflight";
62
63const removedEnvironmentKeys = new Set([
64 "GEMINI_API_KEY",
65 "GOOGLE_API_KEY",
66 "GOOGLE_APPLICATION_CREDENTIALS",
67 "GOOGLE_CLOUD_PROJECT",
68 "GOOGLE_CLOUD_LOCATION",
69 "GOOGLE_CLOUD_QUOTA_PROJECT",
70 "GOOGLE_GENAI_USE_VERTEXAI",
71 "GCLOUD_PROJECT",
72 "CLOUDSDK_CORE_PROJECT",
73 "AGY_ACP_CCPA_PROJECT",
74 "AGY_ACP_ENABLE_OAUTH",
75 "GEMINI_HOME",
76 "AGY_ACP_FORCE_FILE_STORAGE",
77 "ANTIGRAVITY_HARNESS_PATH",
78 "BROWSER",
79 "PYTHONUNBUFFERED",
80 "ELECTRON_RUN_AS_NODE",
81]);
82
83export interface AntigravityProfile {
84 readonly platform: NodeJS.Platform;
85 readonly geminiHome: string;
86 readonly acpDirectory: string;
87 readonly tokenPath: string;
88 readonly tempDirectory: string;
89 readonly browserCommand: string;
90 readonly caBundlePath?: string;
91}
92
93export interface AntigravityAuthConfig {
94 readonly authMethod: AntigravityAuthMethod;
95 readonly apiKey: string;
96 readonly gcpProject: string;
97 readonly gcpLocation: string;
98}
99
100export const ANTIGRAVITY_PERSONAL_AUTH: AntigravityAuthConfig = {
101 authMethod: "oauth-personal",
102 apiKey: "",
103 gcpProject: "",
104 gcpLocation: "",
105};
106
107export function antigravityAuthUsesBrowser(authMethod: AntigravityAuthMethod): boolean {
108 return authMethod === "oauth-personal" || authMethod === "oauth-business";
109}
110
111export function antigravityAuthLabel(authMethod: AntigravityAuthMethod): string {
112 switch (authMethod) {
113 case "oauth-personal":
114 return "Google account";
115 case "oauth-business":
116 return "Gemini Enterprise";
117 case "gemini-api-key":
118 return "Gemini API key";
119 case "agent-platform":
120 return "Agent Platform";
121 }
122}
123
124export function antigravityAuthConfigIssue(auth: AntigravityAuthConfig): string | null {
125 switch (auth.authMethod) {
126 case "oauth-personal":
127 return null;
128 case "oauth-business":
129 return auth.gcpProject && auth.gcpLocation
130 ? null
131 : "Gemini Enterprise needs a GCP project and location in the Antigravity provider settings.";
132 case "gemini-api-key":
133 return auth.apiKey ? null : "Enter a Gemini API key in the Antigravity provider settings.";
134 case "agent-platform":
135 return auth.apiKey || (auth.gcpProject && auth.gcpLocation)
136 ? null
137 : "Agent Platform needs an API key, or a GCP project and location, in the Antigravity provider settings.";
138 }
139}
140
141/**
142 * `auth.type` names the selected method so a native logout clears only that method's credentials
143 * instead of every stored token. Never holds a credential.
144 */
145export function antigravityProfileSettings(auth: AntigravityAuthConfig): string {
146 const gcp = {
147 ...(auth.gcpProject ? { project: auth.gcpProject } : {}),
148 ...(auth.gcpLocation ? { location: auth.gcpLocation } : {}),
149 };
150 return `${encodeProfileSettings({
151 auth: { type: auth.authMethod },
152 ...(Object.keys(gcp).length > 0 ? { gcp } : {}),
153 })}\n`;
154}
155
156export interface AntigravityAuthorizationUrl {
157 readonly authorizationUrl: string;
158 readonly redirectUri: string;
159 readonly state: string;
160}
161
162function authSupportError(detail: string) {
163 return new AcpErrors.AcpTransportError({ detail, cause: undefined });
164}
165
166export function isAntigravitySignInRequiredError(error: unknown): boolean {
167 return (
168 (isAcpRequestError(error) && error.code === -32000) ||
169 (isAcpTransportError(error) && error.detail === ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)
170 );
171}
172
173export interface AntigravityInstanceDirectories {
174 readonly profile: string;
175 /**
176 * It sits beside the profile, not inside it: the agent unpacks members up to 120 characters deep,
177 * and the profile's longer name would push them past Windows' 260-character path limit.
178 */
179 readonly runtimeTemp: string;
180}
181
182/** Hashes the instance ID so case-only differences stay separate on case-insensitive filesystems. */
183export const resolveAntigravityInstanceDirectories = Effect.fn(
184 "resolveAntigravityInstanceDirectories",
185)(function* (stateDir: string, instanceId: ProviderInstanceId) {
186 const crypto = yield* Crypto.Crypto;
187 const path = yield* Path.Path;
188 const key = Hex.encode(yield* crypto.digest("SHA-256", new TextEncoder().encode(instanceId)));
189 return {
190 profile: path.join(stateDir, "providers", "antigravity", key),
191 runtimeTemp: path.join(stateDir, "antigravity-tmp", key.slice(0, 12)),
192 } satisfies AntigravityInstanceDirectories;
193});
194
195function quoteBrowserArgument(value: string): string {
196 return `'${value.replaceAll("'", `'"'"'`)}'`;
197}
198
199function antigravityEnvironment(
200 profile: AntigravityProfile,
201 baseEnv: NodeJS.ProcessEnv,
202 auth: AntigravityAuthConfig,
203 runtimeTempDirectory?: string,
204) {
205 const environment: NodeJS.ProcessEnv = {};
206 for (const [key, value] of Object.entries(baseEnv)) {
207 // Windows treats environment keys as case-insensitive. Remove aliases too.
208 if (!removedEnvironmentKeys.has(key.toUpperCase())) environment[key] = value;
209 }
210 // The agent prefers GOOGLE_API_KEY over the GCP pair for Agent Platform, so the pair goes through
211 // settings.json instead of the environment.
212 const credential =
213 auth.authMethod === "gemini-api-key" && auth.apiKey
214 ? { GEMINI_API_KEY: auth.apiKey }
215 : auth.authMethod === "agent-platform" && auth.apiKey
216 ? { GOOGLE_API_KEY: auth.apiKey }
217 : {};
218 // It unpacks about 1 GB into the system temp directory per launch and a force
219 // kill leaves that behind. Point it at a T3-owned directory so the driver can
220 // reclaim the space.
221 const tempDirectory = runtimeTempDirectory ?? profile.tempDirectory;
222 return {
223 ...environment,
224 ...credential,
225 ...(profile.caBundlePath !== undefined &&
226 baseEnv.SSL_CERT_FILE === undefined &&
227 baseEnv.SSL_CERT_DIR === undefined
228 ? { SSL_CERT_FILE: profile.caBundlePath }
229 : {}),
230 GEMINI_HOME: profile.geminiHome,
231 AGY_ACP_FORCE_FILE_STORAGE: "1",
232 BROWSER: profile.browserCommand,
233 PYTHONUNBUFFERED: "1",
234 ELECTRON_RUN_AS_NODE: "1",
235 ...(profile.platform === "win32"
236 ? { TEMP: tempDirectory, TMP: tempDirectory }
237 : { TMPDIR: tempDirectory }),
238 };
239}
240
241/**
242 * The agent reads its user-global skills under `GEMINI_HOME`, which T3 points
243 * at the private profile. Link the two skill directories back to the user's
244 * real `~/.gemini` so global skills load, while MCP servers, hooks, and
245 * credentials stay isolated.
246 */
247const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(function* (input: {
248 readonly profileDirectory: string;
249 readonly userHome: string;
250 readonly platform: NodeJS.Platform;
251}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> {
252 const fs = yield* FileSystem.FileSystem;
253 const path = yield* Path.Path;
254 const links = antigravityUserSkillDirectories(path, input.profileDirectory);
255 const targets = antigravityUserSkillDirectories(path, path.join(input.userHome, ".gemini"));
256 for (const [link, target] of [
257 [links[0], targets[0]],
258 [links[1], targets[1]],
259 ] as const) {
260 yield* Effect.gen(function* () {
261 const existing = yield* fs.readLink(link).pipe(
262 Effect.map((value): string | undefined => path.resolve(path.dirname(link), value)),
263 Effect.catchReason("PlatformError", "NotFound", () => Effect.undefined),
264 );
265 if (existing === target) return;
266 if (existing !== undefined) {
267 yield* fs.remove(link);
268 }
269 yield* fs.makeDirectory(path.dirname(link), { recursive: true });
270 yield* Effect.tryPromise(() =>
271 NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"),
272 );
273 }).pipe(
274 Effect.catch((error) =>
275 Effect.logWarning("Antigravity user skills are not linked into the profile.", {
276 link,
277 target,
278 error,
279 }),
280 ),
281 );
282 }
283});
284
285export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: {
286 readonly profileDirectory: string;
287 readonly baseEnv?: NodeJS.ProcessEnv;
288 readonly runtimeExecutablePath?: string;
289 readonly platform?: NodeJS.Platform;
290 readonly auth?: AntigravityAuthConfig;
291 readonly userHome?: string;
292 readonly tempDirectory?: string;
293}) {
294 const auth = input.auth ?? ANTIGRAVITY_PERSONAL_AUTH;
295 const fs = yield* FileSystem.FileSystem;
296 const path = yield* Path.Path;
297 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
298 const platform = input.platform ?? (yield* HostProcess.Platform);
299 const userHome =
300 input.userHome ??
301 resolveAntigravityUserHome(
302 platform,
303 input.baseEnv ?? process.env,
304 yield* HostProcess.HomeDirectory,
305 );
306 const runtimeExecutablePath =
307 input.runtimeExecutablePath ??
308 (yield* resolveNodeExecutable("Antigravity sign-in", input.baseEnv).pipe(
309 Effect.mapError(
310 (cause) =>
311 new AcpErrors.AcpTransportError({
312 detail: nodeRuntimeUnavailableMessage("Antigravity sign-in"),
313 cause,
314 }),
315 ),
316 ));
317 const helperExecutable =
318 platform === "win32" ? runtimeExecutablePath.replaceAll("\\", "/") : runtimeExecutablePath;
319 const browserArguments = [helperExecutable, "-e", browserHelperSource, "--", "%s"];
320 const browserCommand = browserArguments.map(quoteBrowserArgument).join(" ");
321 if (
322 browserCommand.includes(platform === "win32" ? ";" : ":") ||
323 helperExecutable.includes("\r") ||
324 helperExecutable.includes("\n") ||
325 helperExecutable.includes("\0") ||
326 helperExecutable.includes("%s")
327 ) {
328 return yield* authSupportError(
329 "The T3 runtime path cannot be used to suppress Antigravity browser launches.",
330 );
331 }
332
333 const geminiHome = path.resolve(input.profileDirectory);
334 const acpDirectory = path.join(geminiHome, "antigravity-acp");
335 const tempDirectory = input.tempDirectory ?? path.join(acpDirectory, "tmp");
336 let caBundlePath: string | undefined;
337 if (platform === "linux") {
338 // Bundled Python may look for certificates at paths absent on this distribution.
339 // Relative paths would resolve differently when the agent runs in the project directory.
340 for (const candidate of [
341 (input.baseEnv ?? process.env).NIX_SSL_CERT_FILE,
342 "/etc/ssl/certs/ca-bundle.crt",
343 "/etc/ssl/certs/ca-certificates.crt",
344 "/etc/pki/tls/certs/ca-bundle.crt",
345 "/etc/ssl/cert.pem",
346 ]) {
347 if (
348 candidate &&
349 path.isAbsolute(candidate) &&
350 (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false)))
351 ) {
352 caBundlePath = candidate;
353 break;
354 }
355 }
356 }
357 const profile: AntigravityProfile = {
358 platform,
359 geminiHome,
360 acpDirectory,
361 tokenPath: path.join(acpDirectory, "acp_token.json"),
362 tempDirectory,
363 browserCommand,
364 ...(caBundlePath === undefined ? {} : { caBundlePath }),
365 };
366 const environment = antigravityEnvironment(profile, input.baseEnv ?? process.env, auth);
367 yield* Effect.gen(function* () {
368 const child = yield* spawner.spawn(
369 ChildProcess.make(helperExecutable, ["-e", browserHelperSource, "--", browserPreflightUrl], {
370 env: environment,
371 extendEnv: false,
372 shell: false,
373 }),
374 );
375 const [stdout, stderr, exitCode] = yield* Effect.all(
376 [
377 collectUint8StreamText({ stream: child.stdout, maxBytes: 4_096 }),
378 collectUint8StreamText({ stream: child.stderr, maxBytes: 4_096 }),
379 child.exitCode,
380 ],
381 { concurrency: "unbounded" },
382 );
383 if (
384 Number(exitCode) !== 0 ||
385 stdout.bytes !== 0 ||
386 stdout.truncated ||
387 stderr.truncated ||
388 stderr.text !== `${ANTIGRAVITY_AUTH_BROWSER_MARKER}"${browserPreflightUrl}"\n`
389 ) {
390 return yield* authSupportError("Antigravity browser suppression could not be verified.");
391 }
392 }).pipe(
393 Effect.scoped,
394 Effect.timeoutOrElse({
395 duration: "5 seconds",
396 orElse: () =>
397 Effect.fail(authSupportError("Antigravity browser suppression verification timed out.")),
398 }),
399 Effect.mapError((error) =>
400 error._tag === "AcpTransportError"
401 ? error
402 : authSupportError("Antigravity browser suppression could not be verified."),
403 ),
404 );
405
406 for (const directory of [geminiHome, acpDirectory, tempDirectory]) {
407 yield* fs
408 .makeDirectory(directory, { recursive: true, mode: 0o700 })
409 .pipe(
410 Effect.mapError(() =>
411 authSupportError("The Antigravity profile directory could not be created."),
412 ),
413 );
414 if (platform !== "win32") {
415 yield* fs
416 .chmod(directory, 0o700)
417 .pipe(
418 Effect.mapError(() =>
419 authSupportError("The Antigravity profile directory permissions could not be set."),
420 ),
421 );
422 }
423 }
424 yield* fs
425 .writeFileString(path.join(acpDirectory, "settings.json"), antigravityProfileSettings(auth))
426 .pipe(
427 Effect.mapError(() =>
428 authSupportError("The Antigravity profile settings could not be written."),
429 ),
430 );
431 yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform });
432 return profile;
433});
434
435export function buildAntigravityAcpSpawnInput(input: {
436 readonly installation: {
437 readonly executablePath: string;
438 readonly harnessPath: string;
439 };
440 readonly profile: AntigravityProfile;
441 readonly cwd: string;
442 readonly baseEnv?: NodeJS.ProcessEnv;
443 readonly auth?: AntigravityAuthConfig;
444 readonly runtimeTempDirectory?: string;
445}): AcpSessionRuntime.AcpSpawnInput {
446 return {
447 command: input.installation.executablePath,
448 args: input.profile.platform === "linux" ? ["--uid="] : [],
449 cwd: input.cwd,
450 env: {
451 ...antigravityEnvironment(
452 input.profile,
453 input.baseEnv ?? process.env,
454 input.auth ?? ANTIGRAVITY_PERSONAL_AUTH,
455 input.runtimeTempDirectory,
456 ),
457 ANTIGRAVITY_HARNESS_PATH: input.installation.harnessPath,
458 },
459 extendEnv: false,
460 };
461}
462
463export const parseAntigravityAuthorizationUrl = Effect.fn("parseAntigravityAuthorizationUrl")(
464 function* (
465 authorizationUrl: string,
466 ): Effect.fn.Return<AntigravityAuthorizationUrl, AcpErrors.AcpError> {
467 const invalidUrl = () =>
468 authSupportError("Antigravity returned an invalid Google sign-in URL.");
469 if (authorizationUrl.length > maxAuthorizationUrlLength || /\s/.test(authorizationUrl)) {
470 return yield* invalidUrl();
471 }
472 const url = yield* decodeUrl(authorizationUrl).pipe(Effect.mapError(invalidUrl));
473 const state = url.searchParams.get("state");
474 const redirectUri = url.searchParams.get("redirect_uri");
475 if (
476 url.origin !== "https://accounts.google.com" ||
477 url.pathname !== "/o/oauth2/v2/auth" ||
478 url.username !== "" ||
479 url.password !== "" ||
480 url.hash !== "" ||
481 url.searchParams.getAll("state").length !== 1 ||
482 url.searchParams.getAll("redirect_uri").length !== 1 ||
483 url.searchParams.getAll("response_type").length !== 1 ||
484 url.searchParams.get("response_type") !== "code" ||
485 state === null ||
486 state.length === 0 ||
487 state.length > 512 ||
488 /\s/.test(state) ||
489 redirectUri === null ||
490 !/^http:\/\/127\.0\.0\.1:[1-9][0-9]{0,4}\/$/.test(redirectUri)
491 ) {
492 return yield* invalidUrl();
493 }
494 const redirect = yield* decodeUrl(redirectUri).pipe(Effect.mapError(invalidUrl));
495 if (Number(redirect.port) < 1_024) return yield* invalidUrl();
496 return { authorizationUrl, redirectUri, state };
497 },
498);
499
500export function makeAntigravityStdoutTransform(
501 input: {
502 readonly onAuthorizationUrl?: (
503 authorizationUrl: string,
504 ) => Effect.Effect<void, AcpErrors.AcpError>;
505 } = {},
506) {
507 const handleLine = Effect.fn("antigravityAuthSupport.handleStdoutLine")(function* (
508 line: Uint8Array,
509 ) {
510 if (!authPrefixBytes.every((byte, index) => line[index] === byte)) return [line];
511 const message = new TextDecoder().decode(line).replace(/\r?\n$/, "");
512 const request = yield* parseAntigravityAuthorizationUrl(
513 message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length),
514 );
515 if (!input.onAuthorizationUrl) {
516 return yield* authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE);
517 }
518 yield* input.onAuthorizationUrl(request.authorizationUrl);
519 return [];
520 });
521
522 return (
523 stdout: ChildProcessSpawner.ChildProcessHandle["stdout"],
524 ): Stream.Stream<Uint8Array, PlatformError.PlatformError | AcpErrors.AcpError> =>
525 Stream.suspend(() => {
526 let pending: Uint8Array[] = [];
527 let pendingBytes = 0;
528 const finishLine = () => {
529 const line = Buffer.concat(pending, pendingBytes);
530 pending = [];
531 pendingBytes = 0;
532 return line;
533 };
534 return stdout.pipe(
535 Stream.mapEffect(
536 Effect.fn("antigravityAuthSupport.splitStdoutLines")(function* (chunk: Uint8Array) {
537 const lines: Uint8Array[] = [];
538 let offset = 0;
539 while (offset < chunk.byteLength) {
540 const newline = chunk.indexOf(10, offset);
541 const end = newline === -1 ? chunk.byteLength : newline + 1;
542 const part = chunk.subarray(offset, end);
543 if (pendingBytes + part.byteLength > maxStdoutLineBytes) {
544 return yield* authSupportError(
545 "Antigravity sent a protocol line that is too large.",
546 );
547 }
548 pending.push(part);
549 pendingBytes += part.byteLength;
550 if (newline !== -1) lines.push(finishLine());
551 offset = end;
552 }
553 return lines;
554 }),
555 ),
556 Stream.flatMap(Stream.fromIterable),
557 Stream.concat(
558 Stream.suspend(() => (pendingBytes > 0 ? Stream.succeed(finishLine()) : Stream.empty)),
559 ),
560 Stream.mapEffect(handleLine),
561 Stream.flatMap(Stream.fromIterable),
562 );
563 });
564}
565
566export function makeAntigravityStderrHandler(
567 input: {
568 readonly onAuthorizationUrl?: (
569 authorizationUrl: string,
570 ) => Effect.Effect<void, AcpErrors.AcpError>;
571 } = {},
572) {
573 let pending = "";
574 const handleLine = (line: string) => {
575 const message = line.endsWith("\r") ? line.slice(0, -1) : line;
576 if (message.length > maxBrowserHelperLineLength) {
577 return Effect.void;
578 }
579 const url = message.startsWith(ANTIGRAVITY_AUTH_STDOUT_PREFIX)
580 ? Effect.succeed(message.slice(ANTIGRAVITY_AUTH_STDOUT_PREFIX.length))
581 : message.startsWith(ANTIGRAVITY_AUTH_BROWSER_MARKER)
582 ? decodeBrowserHelperUrl(message.slice(ANTIGRAVITY_AUTH_BROWSER_MARKER.length))
583 : undefined;
584 if (url === undefined) return Effect.void;
585 return url.pipe(
586 Effect.flatMap(parseAntigravityAuthorizationUrl),
587 Effect.matchEffect({
588 onFailure: () => Effect.void,
589 onSuccess: (request) =>
590 input.onAuthorizationUrl
591 ? input.onAuthorizationUrl(request.authorizationUrl)
592 : Effect.fail(authSupportError(ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE)),
593 }),
594 );
595 };
596
597 return Effect.fn("antigravityAuthSupport.handleStderr")(function* (text: string) {
598 const lines = `${pending}${text}`.split("\n");
599 pending = lines.pop() ?? "";
600 if (pending.length > maxBrowserHelperLineLength) pending = "";
601 yield* Effect.forEach(lines, handleLine, { discard: true });
602 });
603}