opencode-antigravity-auth 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # Antigravity OAuth Plugin for Opencode
2
+
3
+ [![npm version](https://img.shields.io/npm/v/opencode-antigravity-auth.svg)](https://www.npmjs.com/package/opencode-antigravity-auth)
4
+
5
+ Enable Opencode to authenticate against **Antigravity** (Google's IDE) via OAuth so you can use Antigravity rate limits and access models like `gemini-3-pro-high` and `claude-opus-4-5-thinking` with your Google credentials.
6
+
7
+ ## What you get
8
+
9
+ - **Google OAuth sign-in** with automatic token refresh
10
+ - **Antigravity API compatibility** for OpenAI-style requests
11
+ - **Debug logging** for requests and responses
12
+ - **Drop-in setup**—Opencode auto-installs the plugin from config
13
+
14
+ ## Quick start
15
+
16
+ 1) **Add the plugin to config** (`~/.config/opencode/opencode.json` or project `.opencode.json`):
17
+
18
+ ```json
19
+ {
20
+ "plugin": ["opencode-antigravity-auth"]
21
+ }
22
+ ```
23
+
24
+ 2) **Authenticate**
25
+
26
+ - Run `opencode auth login`.
27
+ - Choose Google → **OAuth with Google (Antigravity)**.
28
+ - Sign in via the browser and return to Opencode. If the browser doesn’t open, use the printed link.
29
+
30
+ 3) **Declare the models you want**
31
+
32
+ Add Antigravity models under the `provider.google.models` section of your config:
33
+
34
+ ```json
35
+ {
36
+ "plugin": ["opencode-antigravity-auth"],
37
+ "provider": {
38
+ "google": {
39
+ "models": {
40
+ "gemini-3-pro-high": {
41
+ "name": "Gemini 3 Pro High (Antigravity)",
42
+ "limit": { "context": 1048576, "output": 65535 }
43
+ },
44
+ "gemini-3-pro-low": {
45
+ "name": "Gemini 3 Pro Low (Antigravity)",
46
+ "limit": { "context": 1048576, "output": 65535 }
47
+ },
48
+ "claude-sonnet-4-5": {
49
+ "name": "Claude Sonnet 4.5 (Antigravity)",
50
+ "limit": { "context": 200000, "output": 64000 }
51
+ },
52
+ "claude-sonnet-4-5-thinking": {
53
+ "name": "Claude Sonnet 4.5 Thinking (Antigravity)",
54
+ "limit": { "context": 200000, "output": 64000 }
55
+ },
56
+ "claude-opus-4-5-thinking": {
57
+ "name": "Claude Opus 4.5 Thinking (Antigravity)",
58
+ "limit": { "context": 200000, "output": 64000 }
59
+ },
60
+ "gpt-oss-120b-medium": {
61
+ "name": "GPT-OSS 120B Medium (Antigravity)",
62
+ "limit": { "context": 131072, "output": 32768 }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ 4) **Use a model**
71
+
72
+ ```bash
73
+ opencode run "Hello world" --model=google/gemini-3-pro-high
74
+ ```
75
+
76
+ ## Debugging
77
+
78
+ Enable verbose logging:
79
+
80
+ ```bash
81
+ export OPENCODE_ANTIGRAVITY_DEBUG=1
82
+ ```
83
+
84
+ Logs are written to the current directory (e.g., `antigravity-debug-<timestamp>.log`).
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ npm install
90
+ ```
91
+
92
+ ## Safety, usage, and risk notices
93
+
94
+ ### Intended use
95
+
96
+ - Personal / internal development only
97
+ - Respect internal quotas and data handling policies
98
+ - Not for production services or bypassing intended limits
99
+
100
+ ### Not suitable for
101
+
102
+ - Production application traffic
103
+ - High-volume automated extraction
104
+ - Any use that violates Acceptable Use Policies
105
+
106
+ ### ⚠️ Warning (assumption of risk)
107
+
108
+ By using this plugin, you acknowledge and accept the following:
109
+
110
+ - **Terms of Service risk:** This approach may violate the Terms of Service of AI model providers (Anthropic, OpenAI, etc.). You are solely responsible for ensuring compliance with all applicable terms and policies.
111
+ - **Account risk:** Providers may detect this usage pattern and take punitive action, including suspension, permanent ban, or loss of access to paid subscriptions.
112
+ - **No guarantees:** Providers may change APIs, authentication, or policies at any time, which can break this method without notice.
113
+ - **Assumption of risk:** You assume all legal, financial, and technical risks. The authors and contributors of this project bear no responsibility for any consequences arising from your use.
114
+
115
+ Use at your own risk. Proceed only if you understand and accept these risks.
116
+
117
+ ## Legal
118
+
119
+ - Not affiliated with Google. This is an independent open-source project and is not endorsed by, sponsored by, or affiliated with Google LLC.
120
+ - "Antigravity", "Gemini", "Google Cloud", and "Google" are trademarks of Google LLC.
121
+ - Software is provided "as is", without warranty. You are responsible for complying with Google's Terms of Service and Acceptable Use Policy.
122
+
123
+ ## Credits
124
+
125
+ - Inspired by and different from [opencode-gemini-auth](https://github.com/jenslys/opencode-gemini-auth) by [jenslys](https://github.com/jenslys). Thanks for the groundwork! 🚀
126
+ - Thanks to [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) for the inspiration.
package/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ export {
2
+ AntigravityCLIOAuthPlugin,
3
+ GoogleOAuthPlugin,
4
+ } from "./src/plugin";
5
+
6
+ export {
7
+ authorizeAntigravity,
8
+ exchangeAntigravity,
9
+ } from "./src/antigravity/oauth";
10
+
11
+ export type {
12
+ AntigravityAuthorization,
13
+ AntigravityTokenExchangeResult,
14
+ } from "./src/antigravity/oauth";
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "opencode-antigravity-auth",
3
+ "module": "index.ts",
4
+ "version": "1.0.0",
5
+ "author": "noefabris",
6
+ "repository": "https://github.com/NoeFabris/opencode-antigravity-auth",
7
+ "files": [
8
+ "index.ts",
9
+ "src"
10
+ ],
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "devDependencies": {
14
+ "@opencode-ai/plugin": "^0.15.30",
15
+ "@types/bun": "latest",
16
+ "@types/node": "^24.10.1"
17
+ },
18
+ "peerDependencies": {
19
+ "typescript": "^5"
20
+ },
21
+ "dependencies": {
22
+ "@openauthjs/openauth": "^0.4.3"
23
+ }
24
+ }
@@ -0,0 +1,250 @@
1
+ import { generatePKCE } from "@openauthjs/openauth/pkce";
2
+
3
+ import {
4
+ ANTIGRAVITY_CLIENT_ID,
5
+ ANTIGRAVITY_CLIENT_SECRET,
6
+ ANTIGRAVITY_REDIRECT_URI,
7
+ ANTIGRAVITY_SCOPES,
8
+ ANTIGRAVITY_ENDPOINT_FALLBACKS,
9
+ ANTIGRAVITY_LOAD_ENDPOINTS,
10
+ ANTIGRAVITY_HEADERS,
11
+ } from "../constants";
12
+
13
+ interface PkcePair {
14
+ challenge: string;
15
+ verifier: string;
16
+ }
17
+
18
+ interface AntigravityAuthState {
19
+ verifier: string;
20
+ projectId: string;
21
+ }
22
+
23
+ /**
24
+ * Result returned to the caller after constructing an OAuth authorization URL.
25
+ */
26
+ export interface AntigravityAuthorization {
27
+ url: string;
28
+ verifier: string;
29
+ projectId: string;
30
+ }
31
+
32
+ interface AntigravityTokenExchangeSuccess {
33
+ type: "success";
34
+ refresh: string;
35
+ access: string;
36
+ expires: number;
37
+ email?: string;
38
+ projectId: string;
39
+ }
40
+
41
+ interface AntigravityTokenExchangeFailure {
42
+ type: "failed";
43
+ error: string;
44
+ }
45
+
46
+ export type AntigravityTokenExchangeResult =
47
+ | AntigravityTokenExchangeSuccess
48
+ | AntigravityTokenExchangeFailure;
49
+
50
+ interface AntigravityTokenResponse {
51
+ access_token: string;
52
+ expires_in: number;
53
+ refresh_token: string;
54
+ }
55
+
56
+ interface AntigravityUserInfo {
57
+ email?: string;
58
+ }
59
+
60
+ /**
61
+ * Encode an object into a URL-safe base64 string.
62
+ */
63
+ function encodeState(payload: AntigravityAuthState): string {
64
+ return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
65
+ }
66
+
67
+ /**
68
+ * Decode an OAuth state parameter back into its structured representation.
69
+ */
70
+ function decodeState(state: string): AntigravityAuthState {
71
+ const normalized = state.replace(/-/g, "+").replace(/_/g, "/");
72
+ const padded = normalized.padEnd(normalized.length + ((4 - normalized.length % 4) % 4), "=");
73
+ const json = Buffer.from(padded, "base64").toString("utf8");
74
+ const parsed = JSON.parse(json);
75
+ if (typeof parsed.verifier !== "string") {
76
+ throw new Error("Missing PKCE verifier in state");
77
+ }
78
+ return {
79
+ verifier: parsed.verifier,
80
+ projectId: typeof parsed.projectId === "string" ? parsed.projectId : "",
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Build the Antigravity OAuth authorization URL including PKCE and optional project metadata.
86
+ */
87
+ export async function authorizeAntigravity(projectId = ""): Promise<AntigravityAuthorization> {
88
+ const pkce = (await generatePKCE()) as PkcePair;
89
+
90
+ const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
91
+ url.searchParams.set("client_id", ANTIGRAVITY_CLIENT_ID);
92
+ url.searchParams.set("response_type", "code");
93
+ url.searchParams.set("redirect_uri", ANTIGRAVITY_REDIRECT_URI);
94
+ url.searchParams.set("scope", ANTIGRAVITY_SCOPES.join(" "));
95
+ url.searchParams.set("code_challenge", pkce.challenge);
96
+ url.searchParams.set("code_challenge_method", "S256");
97
+ url.searchParams.set(
98
+ "state",
99
+ encodeState({ verifier: pkce.verifier, projectId: projectId || "" }),
100
+ );
101
+ url.searchParams.set("access_type", "offline");
102
+ url.searchParams.set("prompt", "consent");
103
+
104
+ return {
105
+ url: url.toString(),
106
+ verifier: pkce.verifier,
107
+ projectId: projectId || "",
108
+ };
109
+ }
110
+
111
+ async function fetchProjectID(accessToken: string): Promise<string> {
112
+ const errors: string[] = [];
113
+ // Use CLIProxy-aligned headers for project discovery to match "real" Antigravity clients.
114
+ const loadHeaders: Record<string, string> = {
115
+ Authorization: `Bearer ${accessToken}`,
116
+ "Content-Type": "application/json",
117
+ "User-Agent": "google-api-nodejs-client/9.15.1",
118
+ "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
119
+ "Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"],
120
+ };
121
+
122
+ const loadEndpoints = Array.from(
123
+ new Set<string>([...ANTIGRAVITY_LOAD_ENDPOINTS, ...ANTIGRAVITY_ENDPOINT_FALLBACKS]),
124
+ );
125
+
126
+ for (const baseEndpoint of loadEndpoints) {
127
+ try {
128
+ const url = `${baseEndpoint}/v1internal:loadCodeAssist`;
129
+ const response = await fetch(url, {
130
+ method: "POST",
131
+ headers: loadHeaders,
132
+ body: JSON.stringify({
133
+ metadata: {
134
+ ideType: "IDE_UNSPECIFIED",
135
+ platform: "PLATFORM_UNSPECIFIED",
136
+ pluginType: "GEMINI",
137
+ },
138
+ }),
139
+ });
140
+
141
+ if (!response.ok) {
142
+ const message = await response.text().catch(() => "");
143
+ errors.push(
144
+ `loadCodeAssist ${response.status} at ${baseEndpoint}${
145
+ message ? `: ${message}` : ""
146
+ }`,
147
+ );
148
+ continue;
149
+ }
150
+
151
+ const data = await response.json();
152
+ if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) {
153
+ return data.cloudaicompanionProject;
154
+ }
155
+ if (
156
+ data.cloudaicompanionProject &&
157
+ typeof data.cloudaicompanionProject.id === "string" &&
158
+ data.cloudaicompanionProject.id
159
+ ) {
160
+ return data.cloudaicompanionProject.id;
161
+ }
162
+
163
+ errors.push(`loadCodeAssist missing project id at ${baseEndpoint}`);
164
+ } catch (e) {
165
+ errors.push(
166
+ `loadCodeAssist error at ${baseEndpoint}: ${
167
+ e instanceof Error ? e.message : String(e)
168
+ }`,
169
+ );
170
+ }
171
+ }
172
+
173
+ if (errors.length) {
174
+ console.warn("Failed to resolve Antigravity project via loadCodeAssist:", errors.join("; "));
175
+ }
176
+ return "";
177
+ }
178
+
179
+ /**
180
+ * Exchange an authorization code for Antigravity CLI access and refresh tokens.
181
+ */
182
+ export async function exchangeAntigravity(
183
+ code: string,
184
+ state: string,
185
+ ): Promise<AntigravityTokenExchangeResult> {
186
+ try {
187
+ const { verifier, projectId } = decodeState(state);
188
+
189
+ const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
190
+ method: "POST",
191
+ headers: {
192
+ "Content-Type": "application/x-www-form-urlencoded",
193
+ },
194
+ body: new URLSearchParams({
195
+ client_id: ANTIGRAVITY_CLIENT_ID,
196
+ client_secret: ANTIGRAVITY_CLIENT_SECRET,
197
+ code,
198
+ grant_type: "authorization_code",
199
+ redirect_uri: ANTIGRAVITY_REDIRECT_URI,
200
+ code_verifier: verifier,
201
+ }),
202
+ });
203
+
204
+ if (!tokenResponse.ok) {
205
+ const errorText = await tokenResponse.text();
206
+ return { type: "failed", error: errorText };
207
+ }
208
+
209
+ const tokenPayload = (await tokenResponse.json()) as AntigravityTokenResponse;
210
+
211
+ const userInfoResponse = await fetch(
212
+ "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
213
+ {
214
+ headers: {
215
+ Authorization: `Bearer ${tokenPayload.access_token}`,
216
+ },
217
+ },
218
+ );
219
+
220
+ const userInfo = userInfoResponse.ok
221
+ ? ((await userInfoResponse.json()) as AntigravityUserInfo)
222
+ : {};
223
+
224
+ const refreshToken = tokenPayload.refresh_token;
225
+ if (!refreshToken) {
226
+ return { type: "failed", error: "Missing refresh token in response" };
227
+ }
228
+
229
+ let effectiveProjectId = projectId;
230
+ if (!effectiveProjectId) {
231
+ effectiveProjectId = await fetchProjectID(tokenPayload.access_token);
232
+ }
233
+
234
+ const storedRefresh = `${refreshToken}|${effectiveProjectId || ""}`;
235
+
236
+ return {
237
+ type: "success",
238
+ refresh: storedRefresh,
239
+ access: tokenPayload.access_token,
240
+ expires: Date.now() + tokenPayload.expires_in * 1000,
241
+ email: userInfo.email,
242
+ projectId: effectiveProjectId || "",
243
+ };
244
+ } catch (error) {
245
+ return {
246
+ type: "failed",
247
+ error: error instanceof Error ? error.message : "Unknown error",
248
+ };
249
+ }
250
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Constants used for Antigravity OAuth flows and Cloud Code Assist API integration.
3
+ */
4
+ export const ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
5
+
6
+ /**
7
+ * Client secret issued for the Antigravity OAuth application.
8
+ */
9
+ export const ANTIGRAVITY_CLIENT_SECRET = "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";
10
+
11
+ /**
12
+ * Scopes required for Antigravity integrations.
13
+ */
14
+ export const ANTIGRAVITY_SCOPES: readonly string[] = [
15
+ "https://www.googleapis.com/auth/cloud-platform",
16
+ "https://www.googleapis.com/auth/userinfo.email",
17
+ "https://www.googleapis.com/auth/userinfo.profile",
18
+ "https://www.googleapis.com/auth/cclog",
19
+ "https://www.googleapis.com/auth/experimentsandconfigs",
20
+ ];
21
+
22
+ /**
23
+ * OAuth redirect URI used by the local CLI callback server.
24
+ */
25
+ export const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
26
+
27
+ /**
28
+ * Root endpoints for the Antigravity API (in fallback order).
29
+ * CLIProxy and Vibeproxy use the daily sandbox endpoint first,
30
+ * then fallback to autopush and prod if needed.
31
+ */
32
+ export const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
33
+ export const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
34
+ export const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
35
+
36
+ /**
37
+ * Endpoint fallback order (daily → autopush → prod).
38
+ * Shared across request handling and project discovery to mirror CLIProxy behavior.
39
+ */
40
+ export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
41
+ ANTIGRAVITY_ENDPOINT_DAILY,
42
+ ANTIGRAVITY_ENDPOINT_AUTOPUSH,
43
+ ANTIGRAVITY_ENDPOINT_PROD,
44
+ ] as const;
45
+
46
+ /**
47
+ * Preferred endpoint order for project discovery (prod first, then fallbacks).
48
+ * loadCodeAssist appears to be best supported on prod for managed project resolution.
49
+ */
50
+ export const ANTIGRAVITY_LOAD_ENDPOINTS = [
51
+ ANTIGRAVITY_ENDPOINT_PROD,
52
+ ANTIGRAVITY_ENDPOINT_DAILY,
53
+ ANTIGRAVITY_ENDPOINT_AUTOPUSH,
54
+ ] as const;
55
+
56
+ /**
57
+ * Primary endpoint to use (daily sandbox - same as CLIProxy/Vibeproxy).
58
+ */
59
+ export const ANTIGRAVITY_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
60
+
61
+ export const ANTIGRAVITY_HEADERS = {
62
+ "User-Agent": "antigravity/1.11.5 windows/amd64",
63
+ "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
64
+ "Client-Metadata": '{"ideType":"IDE_UNSPECIFIED","platform":"PLATFORM_UNSPECIFIED","pluginType":"GEMINI"}',
65
+ } as const;
66
+
67
+ /**
68
+ * Provider identifier shared between the plugin loader and credential store.
69
+ */
70
+ export const ANTIGRAVITY_PROVIDER_ID = "google";
@@ -0,0 +1,38 @@
1
+ import type { AuthDetails, OAuthAuthDetails, RefreshParts } from "./types";
2
+
3
+ const ACCESS_TOKEN_EXPIRY_BUFFER_MS = 60 * 1000;
4
+
5
+ export function isOAuthAuth(auth: AuthDetails): auth is OAuthAuthDetails {
6
+ return auth.type === "oauth";
7
+ }
8
+
9
+ /**
10
+ * Splits a packed refresh string into its constituent refresh token and project IDs.
11
+ */
12
+ export function parseRefreshParts(refresh: string): RefreshParts {
13
+ const [refreshToken = "", projectId = "", managedProjectId = ""] = (refresh ?? "").split("|");
14
+ return {
15
+ refreshToken,
16
+ projectId: projectId || undefined,
17
+ managedProjectId: managedProjectId || undefined,
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Serializes refresh token parts into the stored string format.
23
+ */
24
+ export function formatRefreshParts(parts: RefreshParts): string {
25
+ const projectSegment = parts.projectId ?? "";
26
+ const base = `${parts.refreshToken}|${projectSegment}`;
27
+ return parts.managedProjectId ? `${base}|${parts.managedProjectId}` : base;
28
+ }
29
+
30
+ /**
31
+ * Determines whether an access token is expired or missing, with buffer for clock skew.
32
+ */
33
+ export function accessTokenExpired(auth: OAuthAuthDetails): boolean {
34
+ if (!auth.access || typeof auth.expires !== "number") {
35
+ return true;
36
+ }
37
+ return auth.expires <= Date.now() + ACCESS_TOKEN_EXPIRY_BUFFER_MS;
38
+ }
@@ -0,0 +1,65 @@
1
+ import { accessTokenExpired } from "./auth";
2
+ import type { OAuthAuthDetails } from "./types";
3
+
4
+ const authCache = new Map<string, OAuthAuthDetails>();
5
+
6
+ /**
7
+ * Produces a stable cache key from a refresh token string.
8
+ */
9
+ function normalizeRefreshKey(refresh?: string): string | undefined {
10
+ const key = refresh?.trim();
11
+ return key ? key : undefined;
12
+ }
13
+
14
+ /**
15
+ * Returns a cached auth snapshot when available, favoring unexpired tokens.
16
+ */
17
+ export function resolveCachedAuth(auth: OAuthAuthDetails): OAuthAuthDetails {
18
+ const key = normalizeRefreshKey(auth.refresh);
19
+ if (!key) {
20
+ return auth;
21
+ }
22
+
23
+ const cached = authCache.get(key);
24
+ if (!cached) {
25
+ authCache.set(key, auth);
26
+ return auth;
27
+ }
28
+
29
+ if (!accessTokenExpired(auth)) {
30
+ authCache.set(key, auth);
31
+ return auth;
32
+ }
33
+
34
+ if (!accessTokenExpired(cached)) {
35
+ return cached;
36
+ }
37
+
38
+ authCache.set(key, auth);
39
+ return auth;
40
+ }
41
+
42
+ /**
43
+ * Stores the latest auth snapshot keyed by refresh token.
44
+ */
45
+ export function storeCachedAuth(auth: OAuthAuthDetails): void {
46
+ const key = normalizeRefreshKey(auth.refresh);
47
+ if (!key) {
48
+ return;
49
+ }
50
+ authCache.set(key, auth);
51
+ }
52
+
53
+ /**
54
+ * Clears cached auth globally or for a specific refresh token.
55
+ */
56
+ export function clearCachedAuth(refresh?: string): void {
57
+ if (!refresh) {
58
+ authCache.clear();
59
+ return;
60
+ }
61
+ const key = normalizeRefreshKey(refresh);
62
+ if (key) {
63
+ authCache.delete(key);
64
+ }
65
+ }
@@ -0,0 +1,15 @@
1
+ import { createInterface } from "node:readline/promises";
2
+ import { stdin as input, stdout as output } from "node:process";
3
+
4
+ /**
5
+ * Prompts the user for a project ID via stdin/stdout.
6
+ */
7
+ export async function promptProjectId(): Promise<string> {
8
+ const rl = createInterface({ input, output });
9
+ try {
10
+ const answer = await rl.question("Project ID (leave blank to use your default project): ");
11
+ return answer.trim();
12
+ } finally {
13
+ rl.close();
14
+ }
15
+ }