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,205 +0,0 @@
1
- /**
2
- * OpenCode configuration file updater.
3
- *
4
- * Updates ~/.config/opencode/opencode.json(c) with plugin models.
5
- */
6
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
7
- import { join, dirname, resolve } from "node:path";
8
- import { homedir } from "node:os";
9
- import { OPENCODE_MODEL_DEFINITIONS } from "./models";
10
- function isRecord(value) {
11
- return typeof value === "object" && value !== null && !Array.isArray(value);
12
- }
13
- function definitionToPlainObject(def) {
14
- return JSON.parse(JSON.stringify(def));
15
- }
16
- // =============================================================================
17
- // =============================================================================
18
- const PLUGIN_NAME = "opencode-antigravity-auth@latest";
19
- const SCHEMA_URL = "https://opencode.ai/config.json";
20
- const OPENCODE_JSON_FILENAME = "opencode.json";
21
- const OPENCODE_JSONC_FILENAME = "opencode.jsonc";
22
- export function stripJsonCommentsAndTrailingCommas(json) {
23
- return json
24
- .replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (match, group) => (group ? "" : match))
25
- .replace(/,(\s*[}\]])/g, "$1");
26
- }
27
- /**
28
- * Get the opencode config directory path.
29
- */
30
- export function getOpencodeConfigDir() {
31
- const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
32
- return join(xdgConfig, "opencode");
33
- }
34
- /**
35
- * Get the opencode config file path.
36
- *
37
- * Prefers opencode.jsonc when present so we update the active config file
38
- * instead of creating a new opencode.json.
39
- */
40
- export function getOpencodeConfigPath() {
41
- const configDir = getOpencodeConfigDir();
42
- const jsoncPath = join(configDir, OPENCODE_JSONC_FILENAME);
43
- const jsonPath = join(configDir, OPENCODE_JSON_FILENAME);
44
- if (existsSync(jsoncPath)) {
45
- return jsoncPath;
46
- }
47
- if (existsSync(jsonPath)) {
48
- return jsonPath;
49
- }
50
- return jsonPath;
51
- }
52
- /**
53
- * Resolves the active OpenCode config file: explicit `configPath`, then `OPENCODE_CONFIG`,
54
- * then default XDG layout (jsonc preferred).
55
- */
56
- export function resolveActiveOpencodeConfigPath(options = {}) {
57
- if (options.configPath) {
58
- return resolve(options.configPath);
59
- }
60
- const envSource = options.env ?? process.env;
61
- const override = envSource.OPENCODE_CONFIG?.trim();
62
- if (override) {
63
- return resolve(override);
64
- }
65
- return getOpencodeConfigPath();
66
- }
67
- // =============================================================================
68
- // =============================================================================
69
- /**
70
- * Updates the opencode configuration file with plugin models.
71
- *
72
- * This function:
73
- * 1. Reads existing opencode.json/opencode.jsonc (or creates default structure)
74
- * 2. Replaces `provider.google.models` with plugin models
75
- * 3. Writes back to disk with proper formatting
76
- *
77
- * Preserves:
78
- * - $schema and other top-level config keys
79
- * - Non-google provider sections
80
- * - Other settings within google provider (except models)
81
- *
82
- * @param options - Optional configuration (e.g., custom configPath for testing)
83
- * @returns UpdateConfigResult with success status and path
84
- */
85
- export async function updateOpencodeConfig(options = {}) {
86
- const configPath = resolveActiveOpencodeConfigPath(options);
87
- try {
88
- let config;
89
- if (existsSync(configPath)) {
90
- const content = readFileSync(configPath, "utf-8");
91
- config = JSON.parse(stripJsonCommentsAndTrailingCommas(content));
92
- }
93
- else {
94
- config = {
95
- $schema: SCHEMA_URL,
96
- plugin: [],
97
- provider: {},
98
- };
99
- }
100
- if (!config.$schema) {
101
- config.$schema = SCHEMA_URL;
102
- }
103
- if (!config.provider) {
104
- config.provider = {};
105
- }
106
- if (!config.provider.google) {
107
- config.provider.google = {};
108
- }
109
- config.provider.google.models = { ...OPENCODE_MODEL_DEFINITIONS };
110
- const configDir = dirname(configPath);
111
- if (!existsSync(configDir)) {
112
- mkdirSync(configDir, { recursive: true });
113
- }
114
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
115
- return {
116
- success: true,
117
- configPath,
118
- };
119
- }
120
- catch (error) {
121
- return {
122
- success: false,
123
- configPath,
124
- error: error instanceof Error ? error.message : String(error),
125
- };
126
- }
127
- }
128
- /**
129
- * Merges built-in Antigravity/Google model definitions into `provider.google.models`
130
- * without removing user-defined model ids.
131
- *
132
- * For each model id in {@link OPENCODE_MODEL_DEFINITIONS}, plugin fields overwrite
133
- * the same keys on the existing entry so names/limits/variants stay current.
134
- * Custom models (ids not in the plugin map) are left unchanged.
135
- *
136
- * Use on plugin startup; use {@link updateOpencodeConfig} when a full replace is intended.
137
- */
138
- export async function mergeAntigravityGoogleModelsIntoOpencodeConfig(options = {}) {
139
- const configPath = resolveActiveOpencodeConfigPath(options);
140
- try {
141
- let config;
142
- if (existsSync(configPath)) {
143
- const content = readFileSync(configPath, "utf-8");
144
- config = JSON.parse(stripJsonCommentsAndTrailingCommas(content));
145
- }
146
- else {
147
- config = {
148
- $schema: SCHEMA_URL,
149
- plugin: [],
150
- provider: {},
151
- };
152
- }
153
- let needsWrite = false;
154
- if (!config.$schema) {
155
- config.$schema = SCHEMA_URL;
156
- needsWrite = true;
157
- }
158
- if (!config.provider) {
159
- config.provider = {};
160
- needsWrite = true;
161
- }
162
- if (!config.provider.google) {
163
- config.provider.google = {};
164
- needsWrite = true;
165
- }
166
- const google = config.provider.google;
167
- const existingModels = isRecord(google.models) ? { ...google.models } : {};
168
- let modelsTouched = false;
169
- for (const [id, def] of Object.entries(OPENCODE_MODEL_DEFINITIONS)) {
170
- const pluginPlain = definitionToPlainObject(def);
171
- const prev = isRecord(existingModels[id])
172
- ? { ...existingModels[id] }
173
- : {};
174
- const next = { ...prev, ...pluginPlain };
175
- const prevNorm = isRecord(existingModels[id]) ? existingModels[id] : {};
176
- if (JSON.stringify(next) !== JSON.stringify(prevNorm)) {
177
- modelsTouched = true;
178
- }
179
- existingModels[id] = next;
180
- }
181
- if (modelsTouched) {
182
- google.models = existingModels;
183
- needsWrite = true;
184
- }
185
- if (!needsWrite) {
186
- return { success: true, configPath };
187
- }
188
- const configDir = dirname(configPath);
189
- if (!existsSync(configDir)) {
190
- mkdirSync(configDir, { recursive: true });
191
- }
192
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
193
- return {
194
- success: true,
195
- configPath,
196
- };
197
- }
198
- catch (error) {
199
- return {
200
- success: false,
201
- configPath,
202
- error: error instanceof Error ? error.message : String(error),
203
- };
204
- }
205
- }
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './transformer';
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './transformer';
@@ -1,9 +0,0 @@
1
- import type { SignatureStore, StreamingCallbacks, StreamingOptions, ThoughtBuffer } from './types';
2
- export declare function createThoughtBuffer(): ThoughtBuffer;
3
- export declare function transformStreamingPayload(payload: string, transformThinkingParts?: (response: unknown) => unknown): string;
4
- export declare function deduplicateThinkingText(response: unknown, sentBuffer: ThoughtBuffer, displayedThinkingHashes?: Set<string>): unknown;
5
- export declare function transformSseLine(line: string, signatureStore: SignatureStore, thoughtBuffer: ThoughtBuffer, sentThinkingBuffer: ThoughtBuffer, callbacks: StreamingCallbacks, options: StreamingOptions, debugState: {
6
- injected: boolean;
7
- }): string;
8
- export declare function cacheThinkingSignaturesFromResponse(response: unknown, signatureSessionKey: string, signatureStore: SignatureStore, thoughtBuffer: ThoughtBuffer, onCacheSignature?: (sessionKey: string, text: string, signature: string) => void): void;
9
- export declare function createStreamingTransformer(signatureStore: SignatureStore, callbacks: StreamingCallbacks, options?: StreamingOptions): TransformStream<Uint8Array, Uint8Array>;
@@ -1,301 +0,0 @@
1
- import { processImageData } from '../../image-saver';
2
- /**
3
- * Simple string hash for thinking deduplication.
4
- * Uses DJB2-like algorithm.
5
- */
6
- function hashString(str) {
7
- let hash = 5381;
8
- for (let i = 0; i < str.length; i++) {
9
- hash = ((hash << 5) + hash) + str.charCodeAt(i); /* hash * 33 + c */
10
- }
11
- return (hash >>> 0).toString(16);
12
- }
13
- export function createThoughtBuffer() {
14
- const buffer = new Map();
15
- return {
16
- get: (index) => buffer.get(index),
17
- set: (index, text) => buffer.set(index, text),
18
- clear: () => buffer.clear(),
19
- };
20
- }
21
- export function transformStreamingPayload(payload, transformThinkingParts) {
22
- return payload
23
- .split('\n')
24
- .map((line) => {
25
- if (!line.startsWith('data:')) {
26
- return line;
27
- }
28
- const json = line.slice(5).trim();
29
- if (!json) {
30
- return line;
31
- }
32
- try {
33
- const parsed = JSON.parse(json);
34
- if (parsed.response !== undefined) {
35
- const transformed = transformThinkingParts
36
- ? transformThinkingParts(parsed.response)
37
- : parsed.response;
38
- return `data: ${JSON.stringify(transformed)}`;
39
- }
40
- }
41
- catch (_) { }
42
- return line;
43
- })
44
- .join('\n');
45
- }
46
- export function deduplicateThinkingText(response, sentBuffer, displayedThinkingHashes) {
47
- if (!response || typeof response !== 'object')
48
- return response;
49
- const resp = response;
50
- if (Array.isArray(resp.candidates)) {
51
- const newCandidates = resp.candidates.map((candidate, index) => {
52
- const cand = candidate;
53
- if (!cand?.content)
54
- return candidate;
55
- const content = cand.content;
56
- if (!Array.isArray(content.parts))
57
- return candidate;
58
- const newParts = content.parts.map((part) => {
59
- const p = part;
60
- if (p.inlineData) {
61
- const inlineData = p.inlineData;
62
- const result = processImageData({
63
- mimeType: inlineData.mimeType,
64
- data: inlineData.data,
65
- });
66
- if (result) {
67
- return { text: result };
68
- }
69
- }
70
- if (p.thought === true || p.type === 'thinking') {
71
- const fullText = (p.text || p.thinking || '');
72
- if (displayedThinkingHashes) {
73
- const hash = hashString(fullText);
74
- if (displayedThinkingHashes.has(hash)) {
75
- sentBuffer.set(index, fullText);
76
- return null;
77
- }
78
- displayedThinkingHashes.add(hash);
79
- }
80
- const sentText = sentBuffer.get(index) ?? '';
81
- if (fullText.startsWith(sentText)) {
82
- const delta = fullText.slice(sentText.length);
83
- sentBuffer.set(index, fullText);
84
- if (delta) {
85
- return { ...p, text: delta, thinking: delta };
86
- }
87
- return null;
88
- }
89
- sentBuffer.set(index, fullText);
90
- return part;
91
- }
92
- return part;
93
- });
94
- const filteredParts = newParts.filter((p) => p !== null);
95
- return {
96
- ...cand,
97
- content: { ...content, parts: filteredParts },
98
- };
99
- });
100
- return { ...resp, candidates: newCandidates };
101
- }
102
- if (Array.isArray(resp.content)) {
103
- let thinkingIndex = 0;
104
- const newContent = resp.content.map((block) => {
105
- const b = block;
106
- if (b?.type === 'thinking') {
107
- const fullText = (b.thinking || b.text || '');
108
- if (displayedThinkingHashes) {
109
- const hash = hashString(fullText);
110
- if (displayedThinkingHashes.has(hash)) {
111
- sentBuffer.set(thinkingIndex, fullText);
112
- thinkingIndex++;
113
- return null;
114
- }
115
- displayedThinkingHashes.add(hash);
116
- }
117
- const sentText = sentBuffer.get(thinkingIndex) ?? '';
118
- if (fullText.startsWith(sentText)) {
119
- const delta = fullText.slice(sentText.length);
120
- sentBuffer.set(thinkingIndex, fullText);
121
- thinkingIndex++;
122
- if (delta) {
123
- return { ...b, thinking: delta, text: delta };
124
- }
125
- return null;
126
- }
127
- sentBuffer.set(thinkingIndex, fullText);
128
- thinkingIndex++;
129
- return block;
130
- }
131
- return block;
132
- });
133
- const filteredContent = newContent.filter((b) => b !== null);
134
- return { ...resp, content: filteredContent };
135
- }
136
- return response;
137
- }
138
- export function transformSseLine(line, signatureStore, thoughtBuffer, sentThinkingBuffer, callbacks, options, debugState) {
139
- if (!line.startsWith('data:')) {
140
- return line;
141
- }
142
- const json = line.slice(5).trim();
143
- if (!json) {
144
- return line;
145
- }
146
- try {
147
- const parsed = JSON.parse(json);
148
- if (parsed.response !== undefined) {
149
- if (options.cacheSignatures && options.signatureSessionKey) {
150
- cacheThinkingSignaturesFromResponse(parsed.response, options.signatureSessionKey, signatureStore, thoughtBuffer, callbacks.onCacheSignature);
151
- }
152
- let response = deduplicateThinkingText(parsed.response, sentThinkingBuffer, options.displayedThinkingHashes);
153
- if (options.debugText && callbacks.onInjectDebug && !debugState.injected) {
154
- response = callbacks.onInjectDebug(response, options.debugText);
155
- debugState.injected = true;
156
- }
157
- // Note: onInjectSyntheticThinking removed - keep_thinking now uses debugText path
158
- const transformed = callbacks.transformThinkingParts
159
- ? callbacks.transformThinkingParts(response)
160
- : response;
161
- return `data: ${JSON.stringify(transformed)}`;
162
- }
163
- }
164
- catch (_) { }
165
- return line;
166
- }
167
- export function cacheThinkingSignaturesFromResponse(response, signatureSessionKey, signatureStore, thoughtBuffer, onCacheSignature) {
168
- if (!response || typeof response !== 'object')
169
- return;
170
- const resp = response;
171
- if (Array.isArray(resp.candidates)) {
172
- resp.candidates.forEach((candidate, index) => {
173
- const cand = candidate;
174
- if (!cand?.content)
175
- return;
176
- const content = cand.content;
177
- if (!Array.isArray(content.parts))
178
- return;
179
- content.parts.forEach((part) => {
180
- const p = part;
181
- if (p.thought === true || p.type === 'thinking') {
182
- const text = (p.text || p.thinking || '');
183
- if (text) {
184
- const current = thoughtBuffer.get(index) ?? '';
185
- thoughtBuffer.set(index, current + text);
186
- }
187
- }
188
- if (p.thoughtSignature) {
189
- const fullText = thoughtBuffer.get(index) ?? '';
190
- if (fullText) {
191
- const signature = p.thoughtSignature;
192
- onCacheSignature?.(signatureSessionKey, fullText, signature);
193
- signatureStore.set(signatureSessionKey, { text: fullText, signature });
194
- }
195
- }
196
- });
197
- });
198
- }
199
- if (Array.isArray(resp.content)) {
200
- const CLAUDE_BUFFER_KEY = 0; // Use index 0 for Claude's single-stream content
201
- resp.content.forEach((block) => {
202
- const b = block;
203
- if (b?.type === 'thinking') {
204
- const text = (b.thinking || b.text || '');
205
- if (text) {
206
- const current = thoughtBuffer.get(CLAUDE_BUFFER_KEY) ?? '';
207
- thoughtBuffer.set(CLAUDE_BUFFER_KEY, current + text);
208
- }
209
- }
210
- if (b?.signature) {
211
- const fullText = thoughtBuffer.get(CLAUDE_BUFFER_KEY) ?? '';
212
- if (fullText) {
213
- const signature = b.signature;
214
- onCacheSignature?.(signatureSessionKey, fullText, signature);
215
- signatureStore.set(signatureSessionKey, { text: fullText, signature });
216
- }
217
- }
218
- });
219
- }
220
- }
221
- export function createStreamingTransformer(signatureStore, callbacks, options = {}) {
222
- const decoder = new TextDecoder();
223
- const encoder = new TextEncoder();
224
- let buffer = '';
225
- const thoughtBuffer = createThoughtBuffer();
226
- const sentThinkingBuffer = createThoughtBuffer();
227
- const debugState = { injected: false };
228
- let hasSeenUsageMetadata = false;
229
- let watchdogTimer = null;
230
- let isDone = false;
231
- let controllerRef = null;
232
- const resetWatchdog = () => {
233
- if (isDone || !controllerRef)
234
- return;
235
- if (watchdogTimer)
236
- clearTimeout(watchdogTimer);
237
- watchdogTimer = setTimeout(() => {
238
- if (isDone)
239
- return;
240
- isDone = true;
241
- const finish = () => {
242
- try {
243
- controllerRef?.terminate();
244
- }
245
- catch (e) { }
246
- options.onComplete?.();
247
- };
248
- if (options.onWatchdogTimeout) {
249
- Promise.resolve(options.onWatchdogTimeout()).finally(finish);
250
- }
251
- else {
252
- finish();
253
- }
254
- }, 45000); // 45 seconds of silence terminates the stream cleanly
255
- };
256
- return new TransformStream({
257
- start(controller) {
258
- controllerRef = controller;
259
- resetWatchdog();
260
- },
261
- transform(chunk, controller) {
262
- resetWatchdog();
263
- buffer += decoder.decode(chunk, { stream: true });
264
- const lines = buffer.split('\n');
265
- buffer = lines.pop() || '';
266
- for (const line of lines) {
267
- if (line.includes('usageMetadata')) {
268
- hasSeenUsageMetadata = true;
269
- }
270
- const transformedLine = transformSseLine(line, signatureStore, thoughtBuffer, sentThinkingBuffer, callbacks, options, debugState);
271
- controller.enqueue(encoder.encode(transformedLine + '\n'));
272
- }
273
- },
274
- flush(controller) {
275
- isDone = true;
276
- if (watchdogTimer)
277
- clearTimeout(watchdogTimer);
278
- buffer += decoder.decode();
279
- if (buffer) {
280
- if (buffer.includes('usageMetadata')) {
281
- hasSeenUsageMetadata = true;
282
- }
283
- const transformedLine = transformSseLine(buffer, signatureStore, thoughtBuffer, sentThinkingBuffer, callbacks, options, debugState);
284
- controller.enqueue(encoder.encode(transformedLine));
285
- }
286
- if (!hasSeenUsageMetadata) {
287
- const syntheticUsage = {
288
- response: {
289
- usageMetadata: {
290
- promptTokenCount: 0,
291
- candidatesTokenCount: 0,
292
- totalTokenCount: 0,
293
- }
294
- }
295
- };
296
- controller.enqueue(encoder.encode(`\ndata: ${JSON.stringify(syntheticUsage)}\n\n`));
297
- }
298
- options.onComplete?.();
299
- },
300
- });
301
- }
@@ -1,28 +0,0 @@
1
- export interface SignedThinking {
2
- text: string;
3
- signature: string;
4
- }
5
- export interface SignatureStore {
6
- get(sessionKey: string): SignedThinking | undefined;
7
- set(sessionKey: string, value: SignedThinking): void;
8
- has(sessionKey: string): boolean;
9
- delete(sessionKey: string): void;
10
- }
11
- export interface StreamingCallbacks {
12
- onCacheSignature?: (sessionKey: string, text: string, signature: string) => void;
13
- onInjectDebug?: (response: unknown, debugText: string) => unknown;
14
- transformThinkingParts?: (parts: unknown) => unknown;
15
- }
16
- export interface StreamingOptions {
17
- signatureSessionKey?: string;
18
- debugText?: string;
19
- cacheSignatures?: boolean;
20
- displayedThinkingHashes?: Set<string>;
21
- onComplete?: () => void;
22
- onWatchdogTimeout?: () => Promise<void> | void;
23
- }
24
- export interface ThoughtBuffer {
25
- get(index: number): string | undefined;
26
- set(index: number, text: string): void;
27
- clear(): void;
28
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,93 +0,0 @@
1
- import type { AntigravityConfig } from "./config";
2
- export declare const DEBUG_MESSAGE_PREFIX = "[opencode-antigravity-auth debug]";
3
- /**
4
- * Initialize or reinitialize debug state with the given config.
5
- * Call this once at plugin startup after loading config.
6
- */
7
- export declare function initializeDebug(config: AntigravityConfig): void;
8
- export declare function isDebugEnabled(): boolean;
9
- export declare function isDebugTuiEnabled(): boolean;
10
- export declare function getLogFilePath(): string | undefined;
11
- export interface AntigravityDebugContext {
12
- id: string;
13
- streaming: boolean;
14
- startedAt: number;
15
- }
16
- interface AntigravityDebugRequestMeta {
17
- originalUrl: string;
18
- resolvedUrl: string;
19
- method?: string;
20
- headers?: HeadersInit;
21
- body?: BodyInit | null;
22
- streaming: boolean;
23
- projectId?: string;
24
- }
25
- interface AntigravityDebugResponseMeta {
26
- body?: string;
27
- note?: string;
28
- error?: unknown;
29
- headersOverride?: HeadersInit;
30
- }
31
- /**
32
- * Begins a debug trace for an Antigravity request.
33
- */
34
- export declare function startAntigravityDebugRequest(meta: AntigravityDebugRequestMeta): AntigravityDebugContext | null;
35
- /**
36
- * Logs response details for a previously started debug trace.
37
- */
38
- export declare function logAntigravityDebugResponse(context: AntigravityDebugContext | null | undefined, response: Response, meta?: AntigravityDebugResponseMeta): void;
39
- export interface AccountDebugInfo {
40
- index: number;
41
- email?: string;
42
- family: string;
43
- totalAccounts: number;
44
- rateLimitState?: {
45
- claude?: number;
46
- gemini?: number;
47
- };
48
- }
49
- export declare function logAccountContext(label: string, info: AccountDebugInfo): void;
50
- export declare function logRateLimitEvent(accountIndex: number, email: string | undefined, family: string, status: number, retryAfterMs: number, bodyInfo: {
51
- message?: string;
52
- quotaResetTime?: string;
53
- retryDelayMs?: number | null;
54
- reason?: string;
55
- }): void;
56
- export declare function logRateLimitSnapshot(family: string, accounts: Array<{
57
- index: number;
58
- email?: string;
59
- rateLimitResetTimes?: {
60
- claude?: number;
61
- gemini?: number;
62
- };
63
- }>): void;
64
- export declare function logResponseBody(context: AntigravityDebugContext | null | undefined, response: Response, status: number): Promise<string | undefined>;
65
- export declare function logModelFamily(url: string, extractedModel: string | null, family: string): void;
66
- export declare function debugLogToFile(message: string): void;
67
- /**
68
- * Logs a toast message to the debug file.
69
- * This helps correlate what the user saw with debug events.
70
- */
71
- export declare function logToast(message: string, variant: "info" | "warning" | "success" | "error"): void;
72
- /**
73
- * Logs retry attempt information.
74
- * @param maxAttempts - Use -1 for unlimited retries
75
- */
76
- export declare function logRetryAttempt(attempt: number, maxAttempts: number, reason: string, delayMs?: number): void;
77
- /**
78
- * Logs cache hit/miss information from response usage metadata.
79
- */
80
- export declare function logCacheStats(model: string, cacheReadTokens: number, cacheWriteTokens: number, totalInputTokens: number): void;
81
- /**
82
- * Logs quota status for an account.
83
- */
84
- export declare function logQuotaStatus(accountEmail: string | undefined, accountIndex: number, quotaPercent: number, family?: string): void;
85
- /**
86
- * Logs background quota fetch events.
87
- */
88
- export declare function logQuotaFetch(event: "start" | "complete" | "error", accountCount?: number, details?: string): void;
89
- /**
90
- * Logs which model is being used for a request.
91
- */
92
- export declare function logModelUsed(requestedModel: string, actualModel: string, accountEmail?: string): void;
93
- export {};