antigravity-auth 1.6.0 → 1.7.1

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.
Files changed (258) hide show
  1. package/README.md +79 -41
  2. package/dist/cli.js +17854 -0
  3. package/dist/handler.js +25147 -0
  4. package/dist/index.js +25138 -5
  5. package/package.json +66 -54
  6. package/dist/antigravity/oauth.d.ts +0 -30
  7. package/dist/antigravity/oauth.js +0 -170
  8. package/dist/claude/login.d.ts +0 -7
  9. package/dist/claude/login.js +0 -480
  10. package/dist/claude/menu-helpers.d.ts +0 -22
  11. package/dist/claude/menu-helpers.js +0 -281
  12. package/dist/claude/proxy-manager.d.ts +0 -11
  13. package/dist/claude/proxy-manager.js +0 -129
  14. package/dist/claude/proxy.d.ts +0 -1
  15. package/dist/claude/proxy.js +0 -733
  16. package/dist/constants.d.ts +0 -138
  17. package/dist/constants.js +0 -216
  18. package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
  19. package/dist/hooks/auto-update-checker/cache.js +0 -70
  20. package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
  21. package/dist/hooks/auto-update-checker/checker.js +0 -233
  22. package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
  23. package/dist/hooks/auto-update-checker/constants.js +0 -22
  24. package/dist/hooks/auto-update-checker/index.d.ts +0 -33
  25. package/dist/hooks/auto-update-checker/index.js +0 -121
  26. package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
  27. package/dist/hooks/auto-update-checker/logging.js +0 -8
  28. package/dist/hooks/auto-update-checker/types.d.ts +0 -24
  29. package/dist/hooks/auto-update-checker/types.js +0 -1
  30. package/dist/index.d.ts +0 -6
  31. package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
  32. package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
  33. package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
  34. package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
  35. package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
  36. package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
  37. package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
  38. package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
  39. package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
  40. package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
  41. package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
  42. package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
  43. package/dist/opencode/plugin.d.ts +0 -29
  44. package/dist/opencode/plugin.js +0 -2954
  45. package/dist/plugin/accounts.d.ts +0 -173
  46. package/dist/plugin/accounts.js +0 -966
  47. package/dist/plugin/auth.d.ts +0 -20
  48. package/dist/plugin/auth.js +0 -44
  49. package/dist/plugin/cache/index.d.ts +0 -4
  50. package/dist/plugin/cache/index.js +0 -4
  51. package/dist/plugin/cache/signature-cache.d.ts +0 -110
  52. package/dist/plugin/cache/signature-cache.js +0 -347
  53. package/dist/plugin/cache.d.ts +0 -43
  54. package/dist/plugin/cache.js +0 -180
  55. package/dist/plugin/cli.d.ts +0 -26
  56. package/dist/plugin/cli.js +0 -126
  57. package/dist/plugin/config/index.d.ts +0 -15
  58. package/dist/plugin/config/index.js +0 -15
  59. package/dist/plugin/config/loader.d.ts +0 -38
  60. package/dist/plugin/config/loader.js +0 -150
  61. package/dist/plugin/config/models.d.ts +0 -26
  62. package/dist/plugin/config/models.js +0 -95
  63. package/dist/plugin/config/schema.d.ts +0 -144
  64. package/dist/plugin/config/schema.js +0 -458
  65. package/dist/plugin/config/updater.d.ts +0 -76
  66. package/dist/plugin/config/updater.js +0 -205
  67. package/dist/plugin/core/streaming/index.d.ts +0 -2
  68. package/dist/plugin/core/streaming/index.js +0 -2
  69. package/dist/plugin/core/streaming/transformer.d.ts +0 -9
  70. package/dist/plugin/core/streaming/transformer.js +0 -301
  71. package/dist/plugin/core/streaming/types.d.ts +0 -28
  72. package/dist/plugin/core/streaming/types.js +0 -1
  73. package/dist/plugin/debug.d.ts +0 -93
  74. package/dist/plugin/debug.js +0 -375
  75. package/dist/plugin/errors.d.ts +0 -27
  76. package/dist/plugin/errors.js +0 -41
  77. package/dist/plugin/fingerprint.d.ts +0 -69
  78. package/dist/plugin/fingerprint.js +0 -137
  79. package/dist/plugin/image-saver.d.ts +0 -24
  80. package/dist/plugin/image-saver.js +0 -78
  81. package/dist/plugin/logger.d.ts +0 -35
  82. package/dist/plugin/logger.js +0 -67
  83. package/dist/plugin/logging-utils.d.ts +0 -22
  84. package/dist/plugin/logging-utils.js +0 -91
  85. package/dist/plugin/project.d.ts +0 -32
  86. package/dist/plugin/project.js +0 -229
  87. package/dist/plugin/quota.d.ts +0 -34
  88. package/dist/plugin/quota.js +0 -261
  89. package/dist/plugin/recovery/constants.d.ts +0 -21
  90. package/dist/plugin/recovery/constants.js +0 -42
  91. package/dist/plugin/recovery/index.d.ts +0 -11
  92. package/dist/plugin/recovery/index.js +0 -11
  93. package/dist/plugin/recovery/storage.d.ts +0 -23
  94. package/dist/plugin/recovery/storage.js +0 -340
  95. package/dist/plugin/recovery/types.d.ts +0 -115
  96. package/dist/plugin/recovery/types.js +0 -6
  97. package/dist/plugin/recovery.d.ts +0 -60
  98. package/dist/plugin/recovery.js +0 -360
  99. package/dist/plugin/refresh-queue.d.ts +0 -99
  100. package/dist/plugin/refresh-queue.js +0 -235
  101. package/dist/plugin/request-helpers.d.ts +0 -281
  102. package/dist/plugin/request-helpers.js +0 -2200
  103. package/dist/plugin/request.d.ts +0 -110
  104. package/dist/plugin/request.js +0 -1489
  105. package/dist/plugin/rotation.d.ts +0 -182
  106. package/dist/plugin/rotation.js +0 -364
  107. package/dist/plugin/search.d.ts +0 -31
  108. package/dist/plugin/search.js +0 -185
  109. package/dist/plugin/server.d.ts +0 -22
  110. package/dist/plugin/server.js +0 -306
  111. package/dist/plugin/storage.d.ts +0 -136
  112. package/dist/plugin/storage.js +0 -599
  113. package/dist/plugin/stores/signature-store.d.ts +0 -4
  114. package/dist/plugin/stores/signature-store.js +0 -24
  115. package/dist/plugin/thinking-recovery.d.ts +0 -89
  116. package/dist/plugin/thinking-recovery.js +0 -289
  117. package/dist/plugin/token.d.ts +0 -18
  118. package/dist/plugin/token.js +0 -127
  119. package/dist/plugin/transform/claude.d.ts +0 -79
  120. package/dist/plugin/transform/claude.js +0 -256
  121. package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  122. package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
  123. package/dist/plugin/transform/gemini.d.ts +0 -132
  124. package/dist/plugin/transform/gemini.js +0 -659
  125. package/dist/plugin/transform/index.d.ts +0 -14
  126. package/dist/plugin/transform/index.js +0 -9
  127. package/dist/plugin/transform/model-resolver.d.ts +0 -98
  128. package/dist/plugin/transform/model-resolver.js +0 -320
  129. package/dist/plugin/transform/types.d.ts +0 -110
  130. package/dist/plugin/transform/types.js +0 -1
  131. package/dist/plugin/types.d.ts +0 -95
  132. package/dist/plugin/types.js +0 -1
  133. package/dist/plugin/ui/ansi.d.ts +0 -31
  134. package/dist/plugin/ui/ansi.js +0 -45
  135. package/dist/plugin/ui/auth-menu.d.ts +0 -47
  136. package/dist/plugin/ui/auth-menu.js +0 -199
  137. package/dist/plugin/ui/confirm.d.ts +0 -1
  138. package/dist/plugin/ui/confirm.js +0 -14
  139. package/dist/plugin/ui/select.d.ts +0 -22
  140. package/dist/plugin/ui/select.js +0 -243
  141. package/dist/plugin/version.d.ts +0 -18
  142. package/dist/plugin/version.js +0 -79
  143. package/dist/src/antigravity/oauth.d.ts +0 -30
  144. package/dist/src/antigravity/oauth.js +0 -170
  145. package/dist/src/constants.d.ts +0 -138
  146. package/dist/src/constants.js +0 -216
  147. package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
  148. package/dist/src/hooks/auto-update-checker/cache.js +0 -70
  149. package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
  150. package/dist/src/hooks/auto-update-checker/checker.js +0 -233
  151. package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
  152. package/dist/src/hooks/auto-update-checker/constants.js +0 -22
  153. package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
  154. package/dist/src/hooks/auto-update-checker/index.js +0 -121
  155. package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
  156. package/dist/src/hooks/auto-update-checker/logging.js +0 -8
  157. package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
  158. package/dist/src/hooks/auto-update-checker/types.js +0 -1
  159. package/dist/src/index.d.ts +0 -6
  160. package/dist/src/index.js +0 -5
  161. package/dist/src/plugin/accounts.d.ts +0 -173
  162. package/dist/src/plugin/accounts.js +0 -966
  163. package/dist/src/plugin/auth.d.ts +0 -20
  164. package/dist/src/plugin/auth.js +0 -44
  165. package/dist/src/plugin/cache/index.d.ts +0 -4
  166. package/dist/src/plugin/cache/index.js +0 -4
  167. package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
  168. package/dist/src/plugin/cache/signature-cache.js +0 -347
  169. package/dist/src/plugin/cache.d.ts +0 -43
  170. package/dist/src/plugin/cache.js +0 -180
  171. package/dist/src/plugin/cli.d.ts +0 -26
  172. package/dist/src/plugin/cli.js +0 -126
  173. package/dist/src/plugin/config/index.d.ts +0 -15
  174. package/dist/src/plugin/config/index.js +0 -15
  175. package/dist/src/plugin/config/loader.d.ts +0 -38
  176. package/dist/src/plugin/config/loader.js +0 -150
  177. package/dist/src/plugin/config/models.d.ts +0 -26
  178. package/dist/src/plugin/config/models.js +0 -95
  179. package/dist/src/plugin/config/schema.d.ts +0 -144
  180. package/dist/src/plugin/config/schema.js +0 -458
  181. package/dist/src/plugin/config/updater.d.ts +0 -76
  182. package/dist/src/plugin/config/updater.js +0 -205
  183. package/dist/src/plugin/core/streaming/index.d.ts +0 -2
  184. package/dist/src/plugin/core/streaming/index.js +0 -2
  185. package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
  186. package/dist/src/plugin/core/streaming/transformer.js +0 -301
  187. package/dist/src/plugin/core/streaming/types.d.ts +0 -28
  188. package/dist/src/plugin/core/streaming/types.js +0 -1
  189. package/dist/src/plugin/debug.d.ts +0 -93
  190. package/dist/src/plugin/debug.js +0 -375
  191. package/dist/src/plugin/errors.d.ts +0 -27
  192. package/dist/src/plugin/errors.js +0 -41
  193. package/dist/src/plugin/fingerprint.d.ts +0 -69
  194. package/dist/src/plugin/fingerprint.js +0 -137
  195. package/dist/src/plugin/image-saver.d.ts +0 -24
  196. package/dist/src/plugin/image-saver.js +0 -78
  197. package/dist/src/plugin/logger.d.ts +0 -35
  198. package/dist/src/plugin/logger.js +0 -67
  199. package/dist/src/plugin/logging-utils.d.ts +0 -22
  200. package/dist/src/plugin/logging-utils.js +0 -91
  201. package/dist/src/plugin/project.d.ts +0 -32
  202. package/dist/src/plugin/project.js +0 -229
  203. package/dist/src/plugin/quota.d.ts +0 -34
  204. package/dist/src/plugin/quota.js +0 -261
  205. package/dist/src/plugin/recovery/constants.d.ts +0 -21
  206. package/dist/src/plugin/recovery/constants.js +0 -42
  207. package/dist/src/plugin/recovery/index.d.ts +0 -11
  208. package/dist/src/plugin/recovery/index.js +0 -11
  209. package/dist/src/plugin/recovery/storage.d.ts +0 -23
  210. package/dist/src/plugin/recovery/storage.js +0 -340
  211. package/dist/src/plugin/recovery/types.d.ts +0 -115
  212. package/dist/src/plugin/recovery/types.js +0 -6
  213. package/dist/src/plugin/recovery.d.ts +0 -60
  214. package/dist/src/plugin/recovery.js +0 -360
  215. package/dist/src/plugin/refresh-queue.d.ts +0 -99
  216. package/dist/src/plugin/refresh-queue.js +0 -235
  217. package/dist/src/plugin/request-helpers.d.ts +0 -281
  218. package/dist/src/plugin/request-helpers.js +0 -2200
  219. package/dist/src/plugin/request.d.ts +0 -110
  220. package/dist/src/plugin/request.js +0 -1489
  221. package/dist/src/plugin/rotation.d.ts +0 -182
  222. package/dist/src/plugin/rotation.js +0 -364
  223. package/dist/src/plugin/search.d.ts +0 -31
  224. package/dist/src/plugin/search.js +0 -185
  225. package/dist/src/plugin/server.d.ts +0 -22
  226. package/dist/src/plugin/server.js +0 -306
  227. package/dist/src/plugin/storage.d.ts +0 -136
  228. package/dist/src/plugin/storage.js +0 -599
  229. package/dist/src/plugin/stores/signature-store.d.ts +0 -4
  230. package/dist/src/plugin/stores/signature-store.js +0 -24
  231. package/dist/src/plugin/thinking-recovery.d.ts +0 -89
  232. package/dist/src/plugin/thinking-recovery.js +0 -289
  233. package/dist/src/plugin/token.d.ts +0 -18
  234. package/dist/src/plugin/token.js +0 -127
  235. package/dist/src/plugin/transform/claude.d.ts +0 -79
  236. package/dist/src/plugin/transform/claude.js +0 -256
  237. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  238. package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
  239. package/dist/src/plugin/transform/gemini.d.ts +0 -132
  240. package/dist/src/plugin/transform/gemini.js +0 -659
  241. package/dist/src/plugin/transform/index.d.ts +0 -14
  242. package/dist/src/plugin/transform/index.js +0 -9
  243. package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
  244. package/dist/src/plugin/transform/model-resolver.js +0 -320
  245. package/dist/src/plugin/transform/types.d.ts +0 -110
  246. package/dist/src/plugin/transform/types.js +0 -1
  247. package/dist/src/plugin/types.d.ts +0 -95
  248. package/dist/src/plugin/types.js +0 -1
  249. package/dist/src/plugin/ui/ansi.d.ts +0 -31
  250. package/dist/src/plugin/ui/ansi.js +0 -45
  251. package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
  252. package/dist/src/plugin/ui/auth-menu.js +0 -199
  253. package/dist/src/plugin/ui/confirm.d.ts +0 -1
  254. package/dist/src/plugin/ui/confirm.js +0 -14
  255. package/dist/src/plugin/ui/select.d.ts +0 -22
  256. package/dist/src/plugin/ui/select.js +0 -243
  257. package/dist/src/plugin/version.d.ts +0 -18
  258. package/dist/src/plugin/version.js +0 -79
@@ -1,185 +0,0 @@
1
- /**
2
- * Google Search Tool Implementation
3
- *
4
- * Due to Gemini API limitations, native search tools (googleSearch, urlContext)
5
- * cannot be combined with function declarations. This module implements a
6
- * wrapper that makes separate API calls with only the grounding tools enabled.
7
- */
8
- import { ANTIGRAVITY_ENDPOINT, getAntigravityHeaders, SEARCH_MODEL, SEARCH_TIMEOUT_MS, SEARCH_SYSTEM_INSTRUCTION, } from "../constants";
9
- import { createLogger } from "./logger";
10
- const log = createLogger("search");
11
- // ============================================================================
12
- // ============================================================================
13
- let sessionCounter = 0;
14
- const sessionPrefix = `search-${Date.now().toString(36)}`;
15
- function generateRequestId() {
16
- return `search-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
17
- }
18
- function getSessionId() {
19
- sessionCounter++;
20
- return `${sessionPrefix}-${sessionCounter}`;
21
- }
22
- function formatSearchResult(result) {
23
- const lines = [];
24
- lines.push("## Search Results\n");
25
- lines.push(result.text);
26
- lines.push("");
27
- if (result.sources.length > 0) {
28
- lines.push("### Sources");
29
- for (const source of result.sources) {
30
- lines.push(`- [${source.title}](${source.url})`);
31
- }
32
- lines.push("");
33
- }
34
- if (result.urlsRetrieved.length > 0) {
35
- lines.push("### URLs Retrieved");
36
- for (const url of result.urlsRetrieved) {
37
- const status = url.status === "URL_RETRIEVAL_STATUS_SUCCESS" ? "✓" : "✗";
38
- lines.push(`- ${status} ${url.url}`);
39
- }
40
- lines.push("");
41
- }
42
- if (result.searchQueries.length > 0) {
43
- lines.push("### Search Queries Used");
44
- for (const q of result.searchQueries) {
45
- lines.push(`- "${q}"`);
46
- }
47
- }
48
- return lines.join("\n");
49
- }
50
- function parseSearchResponse(data) {
51
- const result = {
52
- text: "",
53
- sources: [],
54
- searchQueries: [],
55
- urlsRetrieved: [],
56
- };
57
- const response = data.response;
58
- if (!response || !response.candidates || response.candidates.length === 0) {
59
- if (data.error) {
60
- result.text = `Error: ${data.error.message ?? "Unknown error"}`;
61
- }
62
- else if (response?.error) {
63
- result.text = `Error: ${response.error.message ?? "Unknown error"}`;
64
- }
65
- return result;
66
- }
67
- const candidate = response.candidates[0];
68
- if (!candidate) {
69
- return result;
70
- }
71
- if (candidate.content?.parts) {
72
- result.text = candidate.content.parts
73
- .map((p) => p.text ?? "")
74
- .filter(Boolean)
75
- .join("\n");
76
- }
77
- if (candidate.groundingMetadata) {
78
- const groundingMeta = candidate.groundingMetadata;
79
- if (groundingMeta.webSearchQueries) {
80
- result.searchQueries = groundingMeta.webSearchQueries;
81
- }
82
- if (groundingMeta.groundingChunks) {
83
- for (const chunk of groundingMeta.groundingChunks) {
84
- if (chunk.web?.uri && chunk.web?.title) {
85
- result.sources.push({
86
- title: chunk.web.title,
87
- url: chunk.web.uri,
88
- });
89
- }
90
- }
91
- }
92
- }
93
- if (candidate.urlContextMetadata?.url_metadata) {
94
- for (const meta of candidate.urlContextMetadata.url_metadata) {
95
- if (meta.retrieved_url) {
96
- result.urlsRetrieved.push({
97
- url: meta.retrieved_url,
98
- status: meta.url_retrieval_status ?? "UNKNOWN",
99
- });
100
- }
101
- }
102
- }
103
- return result;
104
- }
105
- // ============================================================================
106
- // ============================================================================
107
- /**
108
- * Execute a Google Search using the Gemini grounding API.
109
- *
110
- * This makes a SEPARATE API call with only googleSearch/urlContext tools,
111
- * which is required because these tools cannot be combined with function declarations.
112
- */
113
- export async function executeSearch(args, accessToken, projectId, abortSignal) {
114
- const { query, urls, thinking = true } = args;
115
- let prompt = query;
116
- if (urls && urls.length > 0) {
117
- const urlList = urls.join("\n");
118
- prompt = `${query}\n\nURLs to analyze:\n${urlList}`;
119
- }
120
- const tools = [];
121
- tools.push({ googleSearch: {} });
122
- if (urls && urls.length > 0) {
123
- tools.push({ urlContext: {} });
124
- }
125
- const requestPayload = {
126
- systemInstruction: {
127
- parts: [{ text: SEARCH_SYSTEM_INSTRUCTION }],
128
- },
129
- contents: [
130
- {
131
- role: "user",
132
- parts: [{ text: prompt }],
133
- },
134
- ],
135
- tools,
136
- generationConfig: {
137
- temperature: 0,
138
- topP: 1,
139
- },
140
- };
141
- const wrappedBody = {
142
- project: projectId,
143
- model: SEARCH_MODEL,
144
- userAgent: "antigravity",
145
- requestId: generateRequestId(),
146
- request: {
147
- ...requestPayload,
148
- sessionId: getSessionId(),
149
- },
150
- };
151
- const url = `${ANTIGRAVITY_ENDPOINT}/v1internal:generateContent`;
152
- log.debug("Executing search", {
153
- query,
154
- urlCount: urls?.length ?? 0,
155
- thinking,
156
- });
157
- try {
158
- const response = await fetch(url, {
159
- method: "POST",
160
- headers: {
161
- ...getAntigravityHeaders(),
162
- Authorization: `Bearer ${accessToken}`,
163
- "Content-Type": "application/json",
164
- },
165
- body: JSON.stringify(wrappedBody),
166
- signal: abortSignal ?? AbortSignal.timeout(SEARCH_TIMEOUT_MS),
167
- });
168
- if (!response.ok) {
169
- const errorText = await response.text();
170
- log.debug("Search API error", { status: response.status, error: errorText });
171
- return `## Search Error\n\nFailed to execute search: ${response.status} ${response.statusText}\n\n${errorText}\n\nPlease try again with a different query.`;
172
- }
173
- const data = (await response.json());
174
- log.debug("Search response received", { hasResponse: !!data.response });
175
- const result = parseSearchResponse(data);
176
- const formatted = formatSearchResult(result);
177
- log.debug("Search response formatted", { resultLength: formatted.length });
178
- return formatted;
179
- }
180
- catch (error) {
181
- const message = error instanceof Error ? error.message : String(error);
182
- log.debug("Search execution error", { error: message });
183
- return `## Search Error\n\nFailed to execute search: ${message}. Please try again with a different query.`;
184
- }
185
- }
@@ -1,22 +0,0 @@
1
- interface OAuthListenerOptions {
2
- /**
3
- * How long to wait for the OAuth redirect before timing out (in milliseconds).
4
- */
5
- timeoutMs?: number;
6
- }
7
- export interface OAuthListener {
8
- /**
9
- * Resolves with the callback URL once Google redirects back to the local server.
10
- */
11
- waitForCallback(): Promise<URL>;
12
- /**
13
- * Cleanly stop listening for callbacks.
14
- */
15
- close(): Promise<void>;
16
- }
17
- /**
18
- * Starts a lightweight HTTP server that listens for the Antigravity OAuth redirect
19
- * and resolves with the captured callback URL.
20
- */
21
- export declare function startOAuthListener({ timeoutMs }?: OAuthListenerOptions): Promise<OAuthListener>;
22
- export {};
@@ -1,306 +0,0 @@
1
- import { createServer } from "node:http";
2
- import { readFileSync, existsSync } from "node:fs";
3
- import { ANTIGRAVITY_REDIRECT_URI } from "../constants";
4
- const redirectUri = new URL(ANTIGRAVITY_REDIRECT_URI);
5
- const callbackPath = redirectUri.pathname || "/";
6
- /**
7
- * Detect if running in OrbStack Docker with --network host mode.
8
- * OrbStack's host networking only forwards ports bound to 127.0.0.1 to macOS.
9
- */
10
- function isOrbStackDockerHost() {
11
- if (!existsSync("/.dockerenv")) {
12
- return false;
13
- }
14
- try {
15
- if (existsSync("/proc/version")) {
16
- const version = readFileSync("/proc/version", "utf8").toLowerCase();
17
- if (version.includes("orbstack")) {
18
- return true;
19
- }
20
- }
21
- const hostname = process.env.HOSTNAME || "";
22
- if (hostname.startsWith("orbstack-") || hostname.endsWith(".orb") || hostname === "orbstack") {
23
- return true;
24
- }
25
- if (existsSync("/etc/resolv.conf")) {
26
- const resolv = readFileSync("/etc/resolv.conf", "utf8");
27
- if (resolv.includes("orb.local") || resolv.includes("orbstack")) {
28
- return true;
29
- }
30
- }
31
- if (process.platform === "linux" && existsSync("/.dockerenv")) {
32
- if (existsSync("/run/host-services")) {
33
- return true;
34
- }
35
- }
36
- }
37
- catch {
38
- }
39
- return false;
40
- }
41
- /**
42
- * Detect WSL (Windows Subsystem for Linux) environment.
43
- */
44
- function isWSL() {
45
- if (process.platform !== "linux")
46
- return false;
47
- try {
48
- const release = readFileSync("/proc/version", "utf8").toLowerCase();
49
- return release.includes("microsoft") || release.includes("wsl");
50
- }
51
- catch {
52
- return false;
53
- }
54
- }
55
- /**
56
- * Detect remote/SSH environment where localhost may not be accessible from browser.
57
- */
58
- function isRemoteEnvironment() {
59
- if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
60
- return true;
61
- }
62
- if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
63
- return true;
64
- }
65
- return false;
66
- }
67
- /**
68
- * Determine the best bind address for the OAuth callback server.
69
- *
70
- * Priority:
71
- * 1. OPENCODE_ANTIGRAVITY_OAUTH_BIND environment variable (user override)
72
- * 2. OrbStack Docker with --network host: 127.0.0.1 (required for port forwarding)
73
- * 3. WSL/SSH/Remote: 0.0.0.0 (needed for cross-network access)
74
- * 4. Default: 127.0.0.1 (most secure for local development)
75
- */
76
- function getBindAddress() {
77
- const envBind = process.env.OPENCODE_ANTIGRAVITY_OAUTH_BIND;
78
- if (envBind) {
79
- return envBind;
80
- }
81
- if (isOrbStackDockerHost()) {
82
- return "127.0.0.1";
83
- }
84
- if (isWSL() || isRemoteEnvironment()) {
85
- return "0.0.0.0";
86
- }
87
- return "127.0.0.1";
88
- }
89
- /**
90
- * Starts a lightweight HTTP server that listens for the Antigravity OAuth redirect
91
- * and resolves with the captured callback URL.
92
- */
93
- export async function startOAuthListener({ timeoutMs = 5 * 60 * 1000 } = {}) {
94
- const port = redirectUri.port
95
- ? Number.parseInt(redirectUri.port, 10)
96
- : redirectUri.protocol === "https:"
97
- ? 443
98
- : 80;
99
- const origin = `${redirectUri.protocol}//${redirectUri.host}`;
100
- let settled = false;
101
- let resolveCallback;
102
- let rejectCallback;
103
- let timeoutHandle;
104
- const callbackPromise = new Promise((resolve, reject) => {
105
- resolveCallback = (url) => {
106
- if (settled)
107
- return;
108
- settled = true;
109
- if (timeoutHandle)
110
- clearTimeout(timeoutHandle);
111
- resolve(url);
112
- };
113
- rejectCallback = (error) => {
114
- if (settled)
115
- return;
116
- settled = true;
117
- if (timeoutHandle)
118
- clearTimeout(timeoutHandle);
119
- reject(error);
120
- };
121
- });
122
- const successResponse = `<!DOCTYPE html>
123
- <html lang="en">
124
- <head>
125
- <meta charset="utf-8" />
126
- <meta name="viewport" content="width=device-width, initial-scale=1">
127
- <title>Authentication Successful</title>
128
- <style>
129
- :root {
130
- --bg: #FAFAFA;
131
- --card-bg: #FFFFFF;
132
- --text-primary: #1F2937;
133
- --text-secondary: #6B7280;
134
- --accent: #2563EB;
135
- --success: #10B981;
136
- --border: #E5E7EB;
137
- }
138
- @media (prefers-color-scheme: dark) {
139
- :root {
140
- --bg: #111827;
141
- --card-bg: #1F2937;
142
- --text-primary: #F9FAFB;
143
- --text-secondary: #9CA3AF;
144
- --accent: #3B82F6;
145
- --success: #34D399;
146
- --border: #374151;
147
- }
148
- }
149
- body {
150
- margin: 0;
151
- min-height: 100vh;
152
- display: flex;
153
- align-items: center;
154
- justify-content: center;
155
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
156
- background: var(--bg);
157
- color: var(--text-primary);
158
- padding: 1rem;
159
- }
160
- .card {
161
- background: var(--card-bg);
162
- border-radius: 16px;
163
- padding: 3rem 2rem;
164
- width: 100%;
165
- max-width: 400px;
166
- text-align: center;
167
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
168
- border: 1px solid var(--border);
169
- }
170
- .icon-wrapper {
171
- width: 64px;
172
- height: 64px;
173
- background: rgba(16, 185, 129, 0.1);
174
- border-radius: 50%;
175
- display: flex;
176
- align-items: center;
177
- justify-content: center;
178
- margin: 0 auto 1.5rem;
179
- }
180
- .icon {
181
- width: 32px;
182
- height: 32px;
183
- color: var(--success);
184
- }
185
- h1 {
186
- font-size: 1.5rem;
187
- font-weight: 600;
188
- margin: 0 0 0.5rem;
189
- letter-spacing: -0.025em;
190
- }
191
- p {
192
- color: var(--text-secondary);
193
- font-size: 0.95rem;
194
- line-height: 1.5;
195
- margin: 0 0 2rem;
196
- }
197
- .btn {
198
- display: inline-flex;
199
- align-items: center;
200
- justify-content: center;
201
- background: var(--text-primary);
202
- color: var(--card-bg);
203
- font-weight: 500;
204
- padding: 0.75rem 1.5rem;
205
- border-radius: 8px;
206
- text-decoration: none;
207
- transition: opacity 0.2s;
208
- font-size: 0.95rem;
209
- border: none;
210
- cursor: pointer;
211
- width: 100%;
212
- box-sizing: border-box;
213
- }
214
- .btn:hover {
215
- opacity: 0.9;
216
- }
217
- .sub-text {
218
- margin-top: 1rem;
219
- font-size: 0.8rem;
220
- color: var(--text-secondary);
221
- }
222
- </style>
223
- </head>
224
- <body>
225
- <div class="card">
226
- <div class="icon-wrapper">
227
- <svg class="icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
228
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M5 13l4 4L19 7" />
229
- </svg>
230
- </div>
231
- <h1>All set!</h1>
232
- <p>You've successfully authenticated with Antigravity. You can now return to Opencode.</p>
233
- <button class="btn" onclick="closeWindow()">Close this tab</button>
234
- <div class="sub-text">Usage Tip: Most browsers block auto-closing. If the button doesn't work, please close the tab manually.</div>
235
- </div>
236
- <script>
237
- function closeWindow() {
238
- window.close();
239
-
240
- document.querySelector('.btn').textContent = "Tab cannot be closed automatically";
241
- document.querySelector('.btn').style.opacity = "0.5";
242
- document.querySelector('.btn').style.cursor = "default";
243
- }
244
- </script>
245
- </body>
246
- </html>`;
247
- timeoutHandle = setTimeout(() => {
248
- rejectCallback(new Error("Timed out waiting for OAuth callback"));
249
- }, timeoutMs);
250
- timeoutHandle.unref?.();
251
- const server = createServer((request, response) => {
252
- if (!request.url) {
253
- response.writeHead(400, { "Content-Type": "text/plain" });
254
- response.end("Invalid request");
255
- return;
256
- }
257
- const url = new URL(request.url, origin);
258
- if (url.pathname !== callbackPath) {
259
- response.writeHead(404, { "Content-Type": "text/plain" });
260
- response.end("Not found");
261
- return;
262
- }
263
- response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
264
- response.end(successResponse);
265
- resolveCallback(url);
266
- setImmediate(() => {
267
- server.close();
268
- });
269
- });
270
- const bindAddress = getBindAddress();
271
- await new Promise((resolve, reject) => {
272
- const handleError = (error) => {
273
- server.off("error", handleError);
274
- if (error.code === "EADDRINUSE") {
275
- reject(new Error(`Port ${port} is already in use. ` +
276
- `Another process is occupying this port. ` +
277
- `Please terminate the process or try again later.`));
278
- return;
279
- }
280
- reject(error);
281
- };
282
- server.once("error", handleError);
283
- server.listen(port, bindAddress, () => {
284
- server.off("error", handleError);
285
- resolve();
286
- });
287
- });
288
- server.on("error", (error) => {
289
- rejectCallback(error instanceof Error ? error : new Error(String(error)));
290
- });
291
- return {
292
- waitForCallback: () => callbackPromise,
293
- close: () => new Promise((resolve, reject) => {
294
- server.close((error) => {
295
- if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
296
- reject(error);
297
- return;
298
- }
299
- if (!settled) {
300
- rejectCallback(new Error("OAuth listener closed before callback"));
301
- }
302
- resolve();
303
- });
304
- }),
305
- };
306
- }
@@ -1,136 +0,0 @@
1
- import type { HeaderStyle } from "../constants";
2
- /**
3
- * Files/directories that should be gitignored in the config directory.
4
- * These contain sensitive data or machine-specific state.
5
- */
6
- export declare const GITIGNORE_ENTRIES: string[];
7
- /**
8
- * Ensures a .gitignore file exists in the config directory with entries
9
- * for sensitive files. Creates the file if missing, or appends missing
10
- * entries if it already exists.
11
- */
12
- export declare function ensureGitignore(configDir: string): Promise<void>;
13
- /**
14
- * Synchronous version of ensureGitignore for use in sync code paths.
15
- */
16
- export declare function ensureGitignoreSync(configDir: string): void;
17
- export type ModelFamily = "claude" | "gemini";
18
- export type { HeaderStyle };
19
- export interface RateLimitState {
20
- claude?: number;
21
- gemini?: number;
22
- }
23
- export interface RateLimitStateV3 {
24
- claude?: number;
25
- "gemini-antigravity"?: number;
26
- "gemini-cli"?: number;
27
- [key: string]: number | undefined;
28
- }
29
- export interface AccountMetadataV1 {
30
- email?: string;
31
- refreshToken: string;
32
- projectId?: string;
33
- managedProjectId?: string;
34
- addedAt: number;
35
- lastUsed: number;
36
- isRateLimited?: boolean;
37
- rateLimitResetTime?: number;
38
- lastSwitchReason?: "rate-limit" | "initial" | "rotation";
39
- }
40
- export interface AccountStorageV1 {
41
- version: 1;
42
- accounts: AccountMetadataV1[];
43
- activeIndex: number;
44
- }
45
- export interface AccountMetadata {
46
- email?: string;
47
- refreshToken: string;
48
- projectId?: string;
49
- managedProjectId?: string;
50
- addedAt: number;
51
- lastUsed: number;
52
- lastSwitchReason?: "rate-limit" | "initial" | "rotation";
53
- rateLimitResetTimes?: RateLimitState;
54
- }
55
- export interface AccountStorage {
56
- version: 2;
57
- accounts: AccountMetadata[];
58
- activeIndex: number;
59
- }
60
- export type CooldownReason = "auth-failure" | "network-error" | "project-error" | "validation-required";
61
- export interface AccountMetadataV3 {
62
- email?: string;
63
- refreshToken: string;
64
- projectId?: string;
65
- managedProjectId?: string;
66
- addedAt: number;
67
- lastUsed: number;
68
- enabled?: boolean;
69
- proxies?: string[];
70
- lastSwitchReason?: "rate-limit" | "initial" | "rotation";
71
- rateLimitResetTimes?: RateLimitStateV3;
72
- coolingDownUntil?: number;
73
- cooldownReason?: CooldownReason;
74
- /** Per-account device fingerprint for rate limit mitigation */
75
- fingerprint?: import("./fingerprint").Fingerprint;
76
- fingerprintHistory?: import("./fingerprint").FingerprintVersion[];
77
- /** Set when Google asks the user to verify this account before requests can continue. */
78
- verificationRequired?: boolean;
79
- verificationRequiredAt?: number;
80
- verificationRequiredReason?: string;
81
- verificationUrl?: string;
82
- /** Cached soft quota data */
83
- cachedQuota?: Record<string, {
84
- remainingFraction?: number;
85
- resetTime?: string;
86
- modelCount: number;
87
- }>;
88
- cachedQuotaUpdatedAt?: number;
89
- }
90
- export interface AccountStorageV3 {
91
- version: 3;
92
- accounts: AccountMetadataV3[];
93
- activeIndex: number;
94
- activeIndexByFamily?: {
95
- claude?: number;
96
- gemini?: number;
97
- };
98
- }
99
- export interface AccountStorageV4 {
100
- version: 4;
101
- accounts: AccountMetadataV3[];
102
- activeIndex: number;
103
- activeIndexByFamily?: {
104
- claude?: number;
105
- gemini?: number;
106
- };
107
- }
108
- /**
109
- * Gets the config directory path, with the following precedence:
110
- * 1. OPENCODE_CONFIG_DIR env var (if set)
111
- * 2. ~/.config/opencode (all platforms, including Windows)
112
- *
113
- * On Windows, also checks for legacy %APPDATA%\opencode path for migration.
114
- */
115
- declare function getConfigDir(): string;
116
- export declare function getStoragePath(): string;
117
- /**
118
- * Gets the config directory path. Exported for use by other modules.
119
- */
120
- export { getConfigDir };
121
- export declare function deduplicateAccountsByEmail<T extends {
122
- email?: string;
123
- lastUsed?: number;
124
- addedAt?: number;
125
- }>(accounts: T[]): T[];
126
- export declare function migrateV2ToV3(v2: AccountStorage): AccountStorageV3;
127
- export declare function migrateV3ToV4(v3: AccountStorageV3): AccountStorageV4;
128
- export declare function loadAccounts(): Promise<AccountStorageV4 | null>;
129
- export declare function saveAccounts(storage: AccountStorageV4): Promise<void>;
130
- /**
131
- * Save accounts storage by replacing the entire file (no merge).
132
- * Use this for destructive operations like delete where we need to
133
- * remove accounts that would otherwise be merged back from existing storage.
134
- */
135
- export declare function saveAccountsReplace(storage: AccountStorageV4): Promise<void>;
136
- export declare function clearAccounts(): Promise<void>;