opencode-antigravity-auth 1.6.0 → 2.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/README.md +36 -12
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/src/antigravity/oauth.d.ts.map +1 -1
- package/dist/src/antigravity/oauth.js +25 -29
- package/dist/src/antigravity/oauth.js.map +1 -1
- package/dist/src/constants.d.ts +53 -25
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +66 -47
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/cache.js +1 -1
- package/dist/src/hooks/auto-update-checker/checker.d.ts +1 -1
- package/dist/src/hooks/auto-update-checker/checker.js +2 -2
- package/dist/src/hooks/auto-update-checker/index.d.ts +4 -4
- package/dist/src/hooks/auto-update-checker/index.js +6 -6
- package/dist/src/hooks/auto-update-checker/logging.js +1 -1
- package/dist/src/plugin/accounts.d.ts +8 -8
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +13 -7
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/auth.d.ts +1 -1
- package/dist/src/plugin/cache/index.d.ts +1 -1
- package/dist/src/plugin/cache/index.js +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +1 -1
- package/dist/src/plugin/cache/signature-cache.js +1 -1
- package/dist/src/plugin/cache.d.ts +7 -5
- package/dist/src/plugin/cache.d.ts.map +1 -1
- package/dist/src/plugin/cache.js +20 -3
- package/dist/src/plugin/cache.js.map +1 -1
- package/dist/src/plugin/cli.d.ts +3 -3
- package/dist/src/plugin/cli.js +3 -3
- package/dist/src/plugin/config/index.d.ts +2 -2
- package/dist/src/plugin/config/index.js +2 -2
- package/dist/src/plugin/config/loader.d.ts +1 -1
- package/dist/src/plugin/config/loader.js +2 -2
- package/dist/src/plugin/config/models-v2.d.ts +36 -0
- package/dist/src/plugin/config/models-v2.d.ts.map +1 -0
- package/dist/src/plugin/config/models-v2.js +51 -0
- package/dist/src/plugin/config/models-v2.js.map +1 -0
- package/dist/src/plugin/config/models.d.ts +1 -1
- package/dist/src/plugin/config/updater.d.ts +16 -3
- package/dist/src/plugin/config/updater.d.ts.map +1 -1
- package/dist/src/plugin/config/updater.js +53 -10
- package/dist/src/plugin/config/updater.js.map +1 -1
- package/dist/src/plugin/core/streaming/index.d.ts +2 -2
- package/dist/src/plugin/core/streaming/index.js +2 -2
- package/dist/src/plugin/core/streaming/transformer.d.ts +1 -1
- package/dist/src/plugin/core/streaming/transformer.js +1 -1
- package/dist/src/plugin/debug.d.ts +1 -1
- package/dist/src/plugin/debug.js +2 -2
- package/dist/src/plugin/fingerprint.d.ts +8 -5
- package/dist/src/plugin/fingerprint.d.ts.map +1 -1
- package/dist/src/plugin/fingerprint.js +23 -41
- package/dist/src/plugin/fingerprint.js.map +1 -1
- package/dist/src/plugin/logger.d.ts +1 -1
- package/dist/src/plugin/logger.js +2 -2
- package/dist/src/plugin/project.d.ts +4 -4
- package/dist/src/plugin/project.d.ts.map +1 -1
- package/dist/src/plugin/project.js +95 -94
- package/dist/src/plugin/project.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +2 -2
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +12 -8
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/recovery/index.d.ts +3 -3
- package/dist/src/plugin/recovery/index.js +3 -3
- package/dist/src/plugin/recovery/storage.d.ts +1 -1
- package/dist/src/plugin/recovery/storage.js +1 -1
- package/dist/src/plugin/recovery.d.ts +3 -3
- package/dist/src/plugin/recovery.js +3 -3
- package/dist/src/plugin/refresh-queue.d.ts +2 -2
- package/dist/src/plugin/refresh-queue.js +2 -2
- package/dist/src/plugin/request-helpers.d.ts +1 -1
- package/dist/src/plugin/request-helpers.js +5 -5
- package/dist/src/plugin/request.d.ts +9 -6
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +23 -23
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/search.js +7 -7
- package/dist/src/plugin/search.js.map +1 -1
- package/dist/src/plugin/server.js +1 -1
- package/dist/src/plugin/storage.d.ts +3 -3
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +56 -67
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/stores/signature-store.d.ts +1 -1
- package/dist/src/plugin/token.d.ts +1 -1
- package/dist/src/plugin/token.js +5 -5
- package/dist/src/plugin/transform/claude.d.ts +1 -1
- package/dist/src/plugin/transform/claude.js +1 -1
- package/dist/src/plugin/transform/cross-model-sanitizer.js +2 -2
- package/dist/src/plugin/transform/gemini.d.ts +1 -1
- package/dist/src/plugin/transform/index.d.ts +9 -9
- package/dist/src/plugin/transform/index.js +4 -4
- package/dist/src/plugin/transform/model-resolver.d.ts +12 -1
- package/dist/src/plugin/transform/model-resolver.d.ts.map +1 -1
- package/dist/src/plugin/transform/model-resolver.js +26 -4
- package/dist/src/plugin/transform/model-resolver.js.map +1 -1
- package/dist/src/plugin/transform/types.d.ts +1 -1
- package/dist/src/plugin/types.d.ts +26 -2
- package/dist/src/plugin/types.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.d.ts +1 -1
- package/dist/src/plugin/ui/auth-menu.js +4 -4
- package/dist/src/plugin/ui/confirm.js +1 -1
- package/dist/src/plugin/ui/select.js +1 -1
- package/dist/src/plugin/version.d.ts +35 -6
- package/dist/src/plugin/version.d.ts.map +1 -1
- package/dist/src/plugin/version.js +138 -42
- package/dist/src/plugin/version.js.map +1 -1
- package/dist/src/plugin.d.ts +11 -7
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +89 -54
- package/dist/src/plugin.js.map +1 -1
- package/dist/src/v2.d.ts +4 -0
- package/dist/src/v2.d.ts.map +1 -0
- package/dist/src/v2.js +391 -0
- package/dist/src/v2.js.map +1 -0
- package/index.js +4 -0
- package/package.json +15 -7
|
@@ -1,38 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Remote Antigravity version fetcher.
|
|
2
|
+
* Remote Antigravity Hub version fetcher.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 1.
|
|
6
|
-
* 2.
|
|
7
|
-
*
|
|
4
|
+
* Resolution strategy:
|
|
5
|
+
* 1. Hub auto-updater manifest (electron-builder YAML, `version:` field)
|
|
6
|
+
* 2. Hardcoded fallback in constants.ts
|
|
7
|
+
*
|
|
8
|
+
* Manifest versions below ANTIGRAVITY_MINIMUM_VERSION are rejected because
|
|
9
|
+
* Cloud Code no longer serves newer models to those clients.
|
|
8
10
|
*
|
|
9
11
|
* Called once at plugin startup to ensure headers use the latest
|
|
10
12
|
* supported version, avoiding "version no longer supported" errors.
|
|
11
13
|
*
|
|
12
|
-
* @see https://github.com/
|
|
14
|
+
* @see https://github.com/router-for-me/CLIProxyAPI (internal/misc/antigravity_version.go)
|
|
13
15
|
*/
|
|
14
|
-
import { getAntigravityVersion, setAntigravityVersion } from "../constants";
|
|
15
|
-
import { createLogger } from "./logger";
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
import { ANTIGRAVITY_MINIMUM_VERSION, getAntigravityVersion, setAntigravityVersion, } from "../constants.js";
|
|
17
|
+
import { createLogger } from "./logger.js";
|
|
18
|
+
export const ANTIGRAVITY_HUB_MANIFEST_URL = "https://antigravity-hub-auto-updater-974169037036.us-central1.run.app/manifest/latest-arm64-mac.yml";
|
|
19
|
+
const MANIFEST_HEADERS = {
|
|
20
|
+
"User-Agent": "electron-builder",
|
|
21
|
+
"Cache-Control": "no-cache",
|
|
22
|
+
};
|
|
18
23
|
const FETCH_TIMEOUT_MS = 5000;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const MAX_MANIFEST_BYTES = 4096;
|
|
25
|
+
const STRICT_VERSION_REGEX = /^\d{1,6}\.\d{1,6}\.\d{1,6}$/;
|
|
26
|
+
const VERSION_KEY = "version:";
|
|
27
|
+
/**
|
|
28
|
+
* Returns true for plain `major.minor.patch` versions (no prefixes, suffixes, or pre-release tags).
|
|
29
|
+
*/
|
|
30
|
+
export function isStrictVersion(value) {
|
|
31
|
+
return STRICT_VERSION_REGEX.test(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compares two strict versions numerically. Returns a negative number, zero, or a positive number.
|
|
35
|
+
*/
|
|
36
|
+
export function compareVersions(a, b) {
|
|
37
|
+
const left = a.split(".").map(Number);
|
|
38
|
+
const right = b.split(".").map(Number);
|
|
39
|
+
for (let i = 0; i < 3; i += 1) {
|
|
40
|
+
const diff = (left[i] ?? 0) - (right[i] ?? 0);
|
|
41
|
+
if (diff !== 0)
|
|
42
|
+
return diff;
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns true when the version is strict and at least the Cloud Code minimum.
|
|
48
|
+
*/
|
|
49
|
+
export function isSupportedAntigravityVersion(version) {
|
|
50
|
+
return isStrictVersion(version) && compareVersions(version, ANTIGRAVITY_MINIMUM_VERSION) >= 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extracts the top-level `version:` value from an electron-builder update manifest.
|
|
54
|
+
* Indented keys (for example inside `files:`) are ignored. Returns null when the
|
|
55
|
+
* value is missing or not a strict `major.minor.patch` version.
|
|
56
|
+
*/
|
|
57
|
+
export function parseHubManifestVersion(text) {
|
|
58
|
+
for (const line of text.split(/\r?\n/)) {
|
|
59
|
+
if (!line.startsWith(VERSION_KEY))
|
|
60
|
+
continue;
|
|
61
|
+
let value = line.slice(VERSION_KEY.length).trim();
|
|
62
|
+
const commentIndex = value.search(/\s#/);
|
|
63
|
+
if (commentIndex >= 0) {
|
|
64
|
+
value = value.slice(0, commentIndex).trim();
|
|
65
|
+
}
|
|
66
|
+
const quote = value[0];
|
|
67
|
+
if ((quote === "'" || quote === "\"") && value.length >= 2 && value.endsWith(quote)) {
|
|
68
|
+
value = value.slice(1, -1);
|
|
69
|
+
}
|
|
70
|
+
return isStrictVersion(value) ? value : null;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
24
73
|
}
|
|
25
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Reads at most maxBytes of the body. A truncated read drops its trailing partial line.
|
|
76
|
+
*/
|
|
77
|
+
async function readBoundedText(response, maxBytes) {
|
|
78
|
+
const body = response.body;
|
|
79
|
+
if (!body) {
|
|
80
|
+
return (await response.text()).slice(0, maxBytes);
|
|
81
|
+
}
|
|
82
|
+
const reader = body.getReader();
|
|
83
|
+
const decoder = new TextDecoder();
|
|
84
|
+
let text = "";
|
|
85
|
+
let received = 0;
|
|
86
|
+
let truncated = false;
|
|
87
|
+
try {
|
|
88
|
+
while (true) {
|
|
89
|
+
const { done, value } = await reader.read();
|
|
90
|
+
if (done)
|
|
91
|
+
break;
|
|
92
|
+
const remaining = maxBytes - received;
|
|
93
|
+
if (value.byteLength > remaining) {
|
|
94
|
+
text += decoder.decode(value.subarray(0, remaining));
|
|
95
|
+
truncated = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
received += value.byteLength;
|
|
99
|
+
text += decoder.decode(value, { stream: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
reader.cancel().catch(() => undefined);
|
|
104
|
+
}
|
|
105
|
+
if (!truncated) {
|
|
106
|
+
return text + decoder.decode();
|
|
107
|
+
}
|
|
108
|
+
const lastNewline = text.lastIndexOf("\n");
|
|
109
|
+
return lastNewline >= 0 ? text.slice(0, lastNewline + 1) : "";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Fetches the latest Hub version from the auto-updater manifest.
|
|
113
|
+
* Returns null on network errors, non-OK responses, or unparseable manifests.
|
|
114
|
+
*/
|
|
115
|
+
export async function fetchHubManifestVersion(url = ANTIGRAVITY_HUB_MANIFEST_URL) {
|
|
26
116
|
const controller = new AbortController();
|
|
27
117
|
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
28
118
|
try {
|
|
29
|
-
const response = await fetch(url, {
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method: "GET",
|
|
121
|
+
headers: MANIFEST_HEADERS,
|
|
122
|
+
signal: controller.signal,
|
|
123
|
+
});
|
|
30
124
|
if (!response.ok)
|
|
31
125
|
return null;
|
|
32
|
-
|
|
33
|
-
if (maxChars)
|
|
34
|
-
text = text.slice(0, maxChars);
|
|
35
|
-
return parseVersion(text);
|
|
126
|
+
return parseHubManifestVersion(await readBoundedText(response, MAX_MANIFEST_BYTES));
|
|
36
127
|
}
|
|
37
128
|
catch {
|
|
38
129
|
return null;
|
|
@@ -48,33 +139,38 @@ async function tryFetchVersion(url, maxChars) {
|
|
|
48
139
|
export async function initAntigravityVersion() {
|
|
49
140
|
const log = createLogger("version");
|
|
50
141
|
const fallback = getAntigravityVersion();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
source = "api";
|
|
142
|
+
const version = await fetchHubManifestVersion();
|
|
143
|
+
if (!version) {
|
|
144
|
+
setAntigravityVersion(fallback);
|
|
145
|
+
log.info("version-fetch-failed", { fallback });
|
|
146
|
+
return;
|
|
57
147
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
version
|
|
61
|
-
|
|
62
|
-
source = "changelog";
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// 3. Fall back to hardcoded
|
|
66
|
-
source = "fallback";
|
|
67
|
-
setAntigravityVersion(fallback);
|
|
68
|
-
log.info("version-fetch-failed", { fallback });
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
148
|
+
if (!isSupportedAntigravityVersion(version)) {
|
|
149
|
+
setAntigravityVersion(fallback);
|
|
150
|
+
log.warn("version-below-minimum", { version, minimum: ANTIGRAVITY_MINIMUM_VERSION, fallback });
|
|
151
|
+
return;
|
|
71
152
|
}
|
|
72
153
|
if (version !== fallback) {
|
|
73
|
-
log.info("version-updated", { version, source, previous: fallback });
|
|
154
|
+
log.info("version-updated", { version, source: "manifest", previous: fallback });
|
|
74
155
|
}
|
|
75
156
|
else {
|
|
76
|
-
log.debug("version-unchanged", { version, source });
|
|
157
|
+
log.debug("version-unchanged", { version, source: "manifest" });
|
|
77
158
|
}
|
|
78
159
|
setAntigravityVersion(version);
|
|
79
160
|
}
|
|
161
|
+
export const ANTIGRAVITY_VERSION_REFRESH_INTERVAL_MS = 3 * 60 * 60 * 1000;
|
|
162
|
+
let lastVersionCheck = 0;
|
|
163
|
+
let pendingVersionCheck;
|
|
164
|
+
/** Coalesce startup checks and refresh long-lived hosts every few hours. */
|
|
165
|
+
export async function refreshAntigravityVersion() {
|
|
166
|
+
if (pendingVersionCheck)
|
|
167
|
+
return pendingVersionCheck;
|
|
168
|
+
if (lastVersionCheck && Date.now() - lastVersionCheck < ANTIGRAVITY_VERSION_REFRESH_INTERVAL_MS)
|
|
169
|
+
return;
|
|
170
|
+
pendingVersionCheck = initAntigravityVersion().finally(() => {
|
|
171
|
+
lastVersionCheck = Date.now();
|
|
172
|
+
pendingVersionCheck = undefined;
|
|
173
|
+
});
|
|
174
|
+
return pendingVersionCheck;
|
|
175
|
+
}
|
|
80
176
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/plugin/version.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/plugin/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,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AAQ,EAAE,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnF,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1E,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,IAAI,mBAA8C,CAAC;AAEnD,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,IAAI,mBAAmB;QAAE,OAAO,mBAAmB,CAAC;IACpD,IAAI,gBAAgB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,GAAG,uCAAuC;QAAE,OAAO;IACxG,mBAAmB,GAAG,sBAAsB,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;QAC1D,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,mBAAmB,GAAG,SAAS,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
package/dist/src/plugin.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { type HeaderStyle } from "./constants";
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
4
|
-
import
|
|
1
|
+
import { type HeaderStyle } from "./constants.js";
|
|
2
|
+
import type { AntigravityTokenExchangeResult } from "./antigravity/oauth.js";
|
|
3
|
+
import { type ModelFamily } from "./plugin/accounts.js";
|
|
4
|
+
import { type AntigravityConfig } from "./plugin/config/index.js";
|
|
5
|
+
import type { PluginContext, PluginResult } from "./plugin/types.js";
|
|
6
|
+
export declare function persistAccountPool(results: Array<Extract<AntigravityTokenExchangeResult, {
|
|
7
|
+
type: "success";
|
|
8
|
+
}>>, replaceAll?: boolean): Promise<void>;
|
|
5
9
|
/**
|
|
6
10
|
* Creates an Antigravity OAuth plugin for a specific provider ID.
|
|
7
11
|
*/
|
|
8
|
-
export declare const createAntigravityPlugin: (providerId: string) => ({ client, directory }: PluginContext) => Promise<PluginResult>;
|
|
9
|
-
export declare const AntigravityCLIOAuthPlugin: ({ client, directory }: PluginContext) => Promise<PluginResult>;
|
|
10
|
-
export declare const GoogleOAuthPlugin: ({ client, directory }: PluginContext) => Promise<PluginResult>;
|
|
12
|
+
export declare const createAntigravityPlugin: (providerId: string) => ({ client, directory, runtimeVersion, fetch: sendFetch }: PluginContext) => Promise<PluginResult>;
|
|
13
|
+
export declare const AntigravityCLIOAuthPlugin: ({ client, directory, runtimeVersion, fetch: sendFetch }: PluginContext) => Promise<PluginResult>;
|
|
14
|
+
export declare const GoogleOAuthPlugin: ({ client, directory, runtimeVersion, fetch: sendFetch }: PluginContext) => Promise<PluginResult>;
|
|
11
15
|
declare function resolveQuotaFallbackHeaderStyle(input: {
|
|
12
16
|
family: ModelFamily;
|
|
13
17
|
headerStyle: HeaderStyle;
|
package/dist/src/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AA+B1E,OAAO,EAAkB,KAAK,WAAW,EAAwE,MAAM,mBAAmB,CAAC;AAE3I,OAAO,EA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plugin.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
|
-
import { tool } from "@opencode-ai/plugin";
|
|
3
|
-
import { ANTIGRAVITY_DEFAULT_PROJECT_ID,
|
|
4
|
-
import { authorizeAntigravity, exchangeAntigravity } from "./antigravity/oauth";
|
|
5
|
-
import { accessTokenExpired, isOAuthAuth, parseRefreshParts, formatRefreshParts } from "./plugin/auth";
|
|
6
|
-
import { promptAddAnotherAccount, promptLoginMode, promptProjectId } from "./plugin/cli";
|
|
7
|
-
import { ensureProjectContext } from "./plugin/project";
|
|
8
|
-
import { startAntigravityDebugRequest, logAntigravityDebugResponse, logAccountContext, logRateLimitEvent, logRateLimitSnapshot, logResponseBody, logModelFamily, isDebugEnabled, getLogFilePath, initializeDebug, } from "./plugin/debug";
|
|
9
|
-
import { buildThinkingWarmupBody, isGenerativeLanguageRequest, prepareAntigravityRequest, transformAntigravityResponse, } from "./plugin/request";
|
|
10
|
-
import { resolveModelWithTier } from "./plugin/transform/model-resolver";
|
|
11
|
-
import { isEmptyResponseBody, createSyntheticErrorResponse, } from "./plugin/request-helpers";
|
|
12
|
-
import { EmptyResponseError } from "./plugin/errors";
|
|
13
|
-
import { AntigravityTokenRefreshError, refreshAccessToken } from "./plugin/token";
|
|
14
|
-
import { startOAuthListener } from "./plugin/server";
|
|
15
|
-
import { clearAccounts, loadAccounts, saveAccounts, saveAccountsReplace } from "./plugin/storage";
|
|
16
|
-
import { AccountManager, parseRateLimitReason, calculateBackoffMs, computeSoftQuotaCacheTtlMs } from "./plugin/accounts";
|
|
17
|
-
import { createAutoUpdateCheckerHook } from "./hooks/auto-update-checker";
|
|
18
|
-
import { loadConfig, initRuntimeConfig } from "./plugin/config";
|
|
19
|
-
import { createSessionRecoveryHook, getRecoverySuccessToast } from "./plugin/recovery";
|
|
20
|
-
import { checkAccountsQuota } from "./plugin/quota";
|
|
21
|
-
import {
|
|
22
|
-
import { createProactiveRefreshQueue } from "./plugin/refresh-queue";
|
|
23
|
-
import { initLogger, createLogger } from "./plugin/logger";
|
|
24
|
-
import { initHealthTracker, getHealthTracker, initTokenTracker, getTokenTracker } from "./plugin/rotation";
|
|
25
|
-
import {
|
|
26
|
-
import { executeSearch } from "./plugin/search";
|
|
2
|
+
import { tool } from "@opencode-ai/plugin/tool";
|
|
3
|
+
import { ANTIGRAVITY_DEFAULT_PROJECT_ID, ANTIGRAVITY_ENDPOINT, ANTIGRAVITY_PROVIDER_ID, getAntigravityHeaders, getEndpointFallbacks, } from "./constants.js";
|
|
4
|
+
import { authorizeAntigravity, exchangeAntigravity } from "./antigravity/oauth.js";
|
|
5
|
+
import { accessTokenExpired, isOAuthAuth, parseRefreshParts, formatRefreshParts } from "./plugin/auth.js";
|
|
6
|
+
import { promptAddAnotherAccount, promptLoginMode, promptProjectId } from "./plugin/cli.js";
|
|
7
|
+
import { ensureProjectContext } from "./plugin/project.js";
|
|
8
|
+
import { startAntigravityDebugRequest, logAntigravityDebugResponse, logAccountContext, logRateLimitEvent, logRateLimitSnapshot, logResponseBody, logModelFamily, isDebugEnabled, getLogFilePath, initializeDebug, } from "./plugin/debug.js";
|
|
9
|
+
import { buildThinkingWarmupBody, isGenerativeLanguageRequest, prepareAntigravityRequest, transformAntigravityResponse, } from "./plugin/request.js";
|
|
10
|
+
import { resolveModelWithTier } from "./plugin/transform/model-resolver.js";
|
|
11
|
+
import { isEmptyResponseBody, createSyntheticErrorResponse, } from "./plugin/request-helpers.js";
|
|
12
|
+
import { EmptyResponseError } from "./plugin/errors.js";
|
|
13
|
+
import { AntigravityTokenRefreshError, refreshAccessToken } from "./plugin/token.js";
|
|
14
|
+
import { startOAuthListener } from "./plugin/server.js";
|
|
15
|
+
import { clearAccounts, loadAccounts, saveAccounts, saveAccountsReplace } from "./plugin/storage.js";
|
|
16
|
+
import { AccountManager, parseRateLimitReason, calculateBackoffMs, computeSoftQuotaCacheTtlMs } from "./plugin/accounts.js";
|
|
17
|
+
import { createAutoUpdateCheckerHook } from "./hooks/auto-update-checker/index.js";
|
|
18
|
+
import { loadConfig, initRuntimeConfig } from "./plugin/config/index.js";
|
|
19
|
+
import { createSessionRecoveryHook, getRecoverySuccessToast } from "./plugin/recovery.js";
|
|
20
|
+
import { checkAccountsQuota } from "./plugin/quota.js";
|
|
21
|
+
import { acquireDiskSignatureCache } from "./plugin/cache.js";
|
|
22
|
+
import { createProactiveRefreshQueue } from "./plugin/refresh-queue.js";
|
|
23
|
+
import { initLogger, createLogger } from "./plugin/logger.js";
|
|
24
|
+
import { initHealthTracker, getHealthTracker, initTokenTracker, getTokenTracker } from "./plugin/rotation.js";
|
|
25
|
+
import { refreshAntigravityVersion, ANTIGRAVITY_VERSION_REFRESH_INTERVAL_MS } from "./plugin/version.js";
|
|
26
|
+
import { executeSearch } from "./plugin/search.js";
|
|
27
27
|
const MAX_OAUTH_ACCOUNTS = 10;
|
|
28
28
|
const MAX_WARMUP_SESSIONS = 1000;
|
|
29
29
|
const MAX_WARMUP_RETRIES = 2;
|
|
@@ -389,11 +389,12 @@ async function verifyAccountAccess(account, client, providerId) {
|
|
|
389
389
|
Authorization: `Bearer ${refreshedAuth.access}`,
|
|
390
390
|
"Content-Type": "application/json",
|
|
391
391
|
};
|
|
392
|
-
if (projectId) {
|
|
393
|
-
headers["x-goog-user-project"] = projectId;
|
|
394
|
-
}
|
|
395
392
|
const requestBody = {
|
|
393
|
+
project: projectId,
|
|
396
394
|
model: "gemini-3-flash",
|
|
395
|
+
requestType: "agent",
|
|
396
|
+
userAgent: "antigravity",
|
|
397
|
+
requestId: `agent-${crypto.randomUUID()}`,
|
|
397
398
|
request: {
|
|
398
399
|
model: "gemini-3-flash",
|
|
399
400
|
contents: [{ role: "user", parts: [{ text: "ping" }] }],
|
|
@@ -404,7 +405,7 @@ async function verifyAccountAccess(account, client, providerId) {
|
|
|
404
405
|
const timeoutId = setTimeout(() => controller.abort(), 20000);
|
|
405
406
|
let response;
|
|
406
407
|
try {
|
|
407
|
-
response = await fetch(`${
|
|
408
|
+
response = await fetch(`${ANTIGRAVITY_ENDPOINT}/v1internal:streamGenerateContent?alt=sse`, {
|
|
408
409
|
method: "POST",
|
|
409
410
|
headers,
|
|
410
411
|
body: JSON.stringify(requestBody),
|
|
@@ -602,7 +603,7 @@ function clampInt(value, min, max) {
|
|
|
602
603
|
}
|
|
603
604
|
return Math.min(max, Math.max(min, Math.floor(value)));
|
|
604
605
|
}
|
|
605
|
-
async function persistAccountPool(results, replaceAll = false) {
|
|
606
|
+
export async function persistAccountPool(results, replaceAll = false) {
|
|
606
607
|
if (results.length === 0) {
|
|
607
608
|
return;
|
|
608
609
|
}
|
|
@@ -992,18 +993,23 @@ function sleep(ms, signal) {
|
|
|
992
993
|
/**
|
|
993
994
|
* Creates an Antigravity OAuth plugin for a specific provider ID.
|
|
994
995
|
*/
|
|
995
|
-
export const createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
|
|
996
|
+
export const createAntigravityPlugin = (providerId) => async ({ client, directory, runtimeVersion = 1, fetch: sendFetch = globalThis.fetch }) => {
|
|
996
997
|
// Load configuration from files and environment variables
|
|
997
998
|
const config = loadConfig(directory);
|
|
998
999
|
initRuntimeConfig(config);
|
|
999
1000
|
// Cached getAuth function for tool access
|
|
1000
1001
|
let cachedGetAuth = null;
|
|
1002
|
+
const refreshQueues = new Set();
|
|
1003
|
+
const transportManagers = new Set();
|
|
1004
|
+
let disposed = false;
|
|
1001
1005
|
// Initialize debug with config
|
|
1002
1006
|
initializeDebug(config);
|
|
1003
1007
|
// Initialize structured logger for TUI integration
|
|
1004
1008
|
initLogger(client);
|
|
1005
1009
|
// Fetch latest Antigravity version from remote API (non-blocking, falls back to hardcoded)
|
|
1006
|
-
await
|
|
1010
|
+
await refreshAntigravityVersion();
|
|
1011
|
+
const versionRefreshTimer = setInterval(() => { void refreshAntigravityVersion(); }, ANTIGRAVITY_VERSION_REFRESH_INTERVAL_MS);
|
|
1012
|
+
versionRefreshTimer.unref?.();
|
|
1007
1013
|
// Initialize health tracker for hybrid strategy
|
|
1008
1014
|
if (config.health_score) {
|
|
1009
1015
|
initHealthTracker({
|
|
@@ -1026,19 +1032,21 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1026
1032
|
}
|
|
1027
1033
|
// Initialize disk signature cache if keep_thinking is enabled
|
|
1028
1034
|
// This integrates with the in-memory cacheSignature/getCachedSignature functions
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1035
|
+
const releaseSignatureCache = config.keep_thinking
|
|
1036
|
+
? acquireDiskSignatureCache(config.signature_cache)
|
|
1037
|
+
: undefined;
|
|
1032
1038
|
// Initialize session recovery hook with full context
|
|
1033
|
-
const sessionRecovery =
|
|
1034
|
-
|
|
1039
|
+
const sessionRecovery = runtimeVersion === 1
|
|
1040
|
+
? createSessionRecoveryHook({ client, directory }, config)
|
|
1041
|
+
: null;
|
|
1042
|
+
const updateChecker = runtimeVersion === 1 ? createAutoUpdateCheckerHook(client, directory, {
|
|
1035
1043
|
showStartupToast: true,
|
|
1036
1044
|
autoUpdate: config.auto_update,
|
|
1037
|
-
});
|
|
1045
|
+
}) : null;
|
|
1038
1046
|
// Event handler for session recovery and updates
|
|
1039
1047
|
const eventHandler = async (input) => {
|
|
1040
1048
|
// Forward to update checker
|
|
1041
|
-
await updateChecker
|
|
1049
|
+
await updateChecker?.event(input);
|
|
1042
1050
|
// Track if this is a child session (subagent, background task)
|
|
1043
1051
|
// This is used to filter toasts based on toast_scope config
|
|
1044
1052
|
if (input.event.type === "session.created") {
|
|
@@ -1135,6 +1143,23 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1135
1143
|
},
|
|
1136
1144
|
});
|
|
1137
1145
|
return {
|
|
1146
|
+
async flush() {
|
|
1147
|
+
await Promise.allSettled([...transportManagers].map((manager) => manager.flushSaveToDisk()));
|
|
1148
|
+
transportManagers.clear();
|
|
1149
|
+
},
|
|
1150
|
+
async dispose() {
|
|
1151
|
+
if (disposed)
|
|
1152
|
+
return;
|
|
1153
|
+
disposed = true;
|
|
1154
|
+
releaseSignatureCache?.();
|
|
1155
|
+
clearInterval(versionRefreshTimer);
|
|
1156
|
+
for (const queue of refreshQueues)
|
|
1157
|
+
queue.stop();
|
|
1158
|
+
refreshQueues.clear();
|
|
1159
|
+
await Promise.allSettled([...transportManagers].map((manager) => manager.flushSaveToDisk()));
|
|
1160
|
+
transportManagers.clear();
|
|
1161
|
+
cachedGetAuth = null;
|
|
1162
|
+
},
|
|
1138
1163
|
event: eventHandler,
|
|
1139
1164
|
tool: {
|
|
1140
1165
|
google_search: googleSearchTool,
|
|
@@ -1142,11 +1167,22 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1142
1167
|
auth: {
|
|
1143
1168
|
provider: providerId,
|
|
1144
1169
|
loader: async (getAuth, provider) => {
|
|
1170
|
+
if (disposed)
|
|
1171
|
+
throw new Error("Antigravity plugin has been disposed");
|
|
1172
|
+
if (runtimeVersion === 2) {
|
|
1173
|
+
for (const queue of refreshQueues)
|
|
1174
|
+
queue.stop();
|
|
1175
|
+
refreshQueues.clear();
|
|
1176
|
+
await Promise.allSettled([...transportManagers].map((manager) => manager.flushSaveToDisk()));
|
|
1177
|
+
transportManagers.clear();
|
|
1178
|
+
}
|
|
1145
1179
|
// Cache getAuth for tool access
|
|
1146
1180
|
cachedGetAuth = getAuth;
|
|
1147
1181
|
const auth = await getAuth();
|
|
1148
1182
|
// If OpenCode has no valid OAuth auth, clear any stale account storage
|
|
1149
1183
|
if (!isOAuthAuth(auth)) {
|
|
1184
|
+
if (runtimeVersion === 2)
|
|
1185
|
+
return {};
|
|
1150
1186
|
try {
|
|
1151
1187
|
await clearAccounts();
|
|
1152
1188
|
}
|
|
@@ -1161,7 +1197,10 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1161
1197
|
const storedAccounts = await loadAccounts();
|
|
1162
1198
|
// Note: AccountManager now ensures the current auth is always included in accounts
|
|
1163
1199
|
const accountManager = await AccountManager.loadFromDisk(auth);
|
|
1200
|
+
if (disposed)
|
|
1201
|
+
throw new Error("Antigravity plugin has been disposed");
|
|
1164
1202
|
activeAccountManager = accountManager;
|
|
1203
|
+
transportManagers.add(accountManager);
|
|
1165
1204
|
if (accountManager.getAccountCount() > 0) {
|
|
1166
1205
|
accountManager.requestSaveToDisk();
|
|
1167
1206
|
}
|
|
@@ -1175,6 +1214,7 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1175
1214
|
});
|
|
1176
1215
|
refreshQueue.setAccountManager(accountManager);
|
|
1177
1216
|
refreshQueue.start();
|
|
1217
|
+
refreshQueues.add(refreshQueue);
|
|
1178
1218
|
}
|
|
1179
1219
|
if (isDebugEnabled()) {
|
|
1180
1220
|
const logPath = getLogFilePath();
|
|
@@ -1197,14 +1237,14 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1197
1237
|
}
|
|
1198
1238
|
}
|
|
1199
1239
|
return {
|
|
1200
|
-
apiKey: "",
|
|
1240
|
+
apiKey: "antigravity-oauth",
|
|
1201
1241
|
async fetch(input, init) {
|
|
1202
1242
|
if (!isGenerativeLanguageRequest(input)) {
|
|
1203
|
-
return
|
|
1243
|
+
return sendFetch(input, init);
|
|
1204
1244
|
}
|
|
1205
1245
|
const latestAuth = await getAuth();
|
|
1206
1246
|
if (!isOAuthAuth(latestAuth)) {
|
|
1207
|
-
return
|
|
1247
|
+
return sendFetch(input, init);
|
|
1208
1248
|
}
|
|
1209
1249
|
if (accountManager.getAccountCount() === 0) {
|
|
1210
1250
|
throw new Error("No Antigravity accounts configured. Run `opencode auth login`.");
|
|
@@ -1487,7 +1527,7 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1487
1527
|
});
|
|
1488
1528
|
try {
|
|
1489
1529
|
pushDebug("thinking-warmup: start");
|
|
1490
|
-
const warmupResponse = await
|
|
1530
|
+
const warmupResponse = await sendFetch(warmupUrl, warmupInit);
|
|
1491
1531
|
const transformed = await transformAntigravityResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId);
|
|
1492
1532
|
await transformed.text();
|
|
1493
1533
|
markWarmupSuccess(prepared.sessionId);
|
|
@@ -1568,19 +1608,14 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1568
1608
|
// Track capacity retries per endpoint to prevent infinite loops
|
|
1569
1609
|
let capacityRetryCount = 0;
|
|
1570
1610
|
let lastEndpointIndex = -1;
|
|
1571
|
-
|
|
1611
|
+
const endpoints = getEndpointFallbacks(headerStyle);
|
|
1612
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
1572
1613
|
// Reset capacity retry counter when switching to a new endpoint
|
|
1573
1614
|
if (i !== lastEndpointIndex) {
|
|
1574
1615
|
capacityRetryCount = 0;
|
|
1575
1616
|
lastEndpointIndex = i;
|
|
1576
1617
|
}
|
|
1577
|
-
const currentEndpoint =
|
|
1578
|
-
// Skip sandbox endpoints for Gemini CLI models - they only work with Antigravity quota
|
|
1579
|
-
// Gemini CLI models must use production endpoint (cloudcode-pa.googleapis.com)
|
|
1580
|
-
if (headerStyle === "gemini-cli" && currentEndpoint !== ANTIGRAVITY_ENDPOINT_PROD) {
|
|
1581
|
-
pushDebug(`Skipping sandbox endpoint ${currentEndpoint} for gemini-cli headerStyle`);
|
|
1582
|
-
continue;
|
|
1583
|
-
}
|
|
1618
|
+
const currentEndpoint = endpoints[i];
|
|
1584
1619
|
try {
|
|
1585
1620
|
const prepared = prepareAntigravityRequest(input, init, accessToken, projectContext.effectiveProjectId, currentEndpoint, headerStyle, forceThinkingRecovery, {
|
|
1586
1621
|
claudeToolHardening: config.claude_tool_hardening,
|
|
@@ -1625,7 +1660,7 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1625
1660
|
if (config.account_selection_strategy === 'hybrid') {
|
|
1626
1661
|
tokenConsumed = getTokenTracker().consume(account.index);
|
|
1627
1662
|
}
|
|
1628
|
-
const response = await
|
|
1663
|
+
const response = await sendFetch(prepared.request, prepared.init);
|
|
1629
1664
|
pushDebug(`status=${response.status} ${response.statusText}`);
|
|
1630
1665
|
// Handle 429 rate limit (or Service Overloaded) with improved logic
|
|
1631
1666
|
if (response.status === 429 || response.status === 503 || response.status === 529) {
|
|
@@ -1822,7 +1857,7 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1822
1857
|
const shouldRetryEndpoint = (response.status === 403 ||
|
|
1823
1858
|
response.status === 404 ||
|
|
1824
1859
|
response.status >= 500);
|
|
1825
|
-
if (shouldRetryEndpoint && i <
|
|
1860
|
+
if (shouldRetryEndpoint && i < endpoints.length - 1) {
|
|
1826
1861
|
await logResponseBody(debugContext, response, response.status);
|
|
1827
1862
|
lastFailure = createFailureContext(response);
|
|
1828
1863
|
continue;
|
|
@@ -1924,7 +1959,7 @@ export const createAntigravityPlugin = (providerId) => async ({ client, director
|
|
|
1924
1959
|
headers: { "Content-Type": "application/json" }
|
|
1925
1960
|
});
|
|
1926
1961
|
}
|
|
1927
|
-
if (i <
|
|
1962
|
+
if (i < endpoints.length - 1) {
|
|
1928
1963
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1929
1964
|
continue;
|
|
1930
1965
|
}
|