opencode-antigravity-auth 1.6.5-beta.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 +0 -28
- package/dist/src/antigravity/oauth.d.ts.map +1 -1
- package/dist/src/antigravity/oauth.js +25 -103
- package/dist/src/antigravity/oauth.js.map +1 -1
- package/dist/src/constants.d.ts +53 -32
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +64 -56
- 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 +9 -10
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +14 -13
- 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 +4 -6
- package/dist/src/plugin/cli.d.ts.map +1 -1
- package/dist/src/plugin/cli.js +5 -11
- package/dist/src/plugin/cli.js.map +1 -1
- 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 -5
- 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 -4
- package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.js +8 -16
- package/dist/src/plugin/ui/auth-menu.js.map +1 -1
- 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 -8
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +97 -276
- 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 +14 -6
package/dist/src/plugin/debug.js
CHANGED
|
@@ -2,8 +2,8 @@ import { createWriteStream, mkdirSync, readdirSync, statSync, unlinkSync } from
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { env } from "node:process";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
-
import { deriveDebugPolicy, formatAccountContextLabel, formatAccountLabel, formatBodyPreviewForLog, formatErrorForLog, isTruthyFlag, truncateTextForLog, } from "./logging-utils";
|
|
6
|
-
import { ensureGitignoreSync } from "./storage";
|
|
5
|
+
import { deriveDebugPolicy, formatAccountContextLabel, formatAccountLabel, formatBodyPreviewForLog, formatErrorForLog, isTruthyFlag, truncateTextForLog, } from "./logging-utils.js";
|
|
6
|
+
import { ensureGitignoreSync } from "./storage.js";
|
|
7
7
|
const MAX_BODY_PREVIEW_CHARS = 12000;
|
|
8
8
|
const MAX_BODY_LOG_CHARS = 50000;
|
|
9
9
|
export const DEBUG_MESSAGE_PREFIX = "[opencode-antigravity-auth debug]";
|
|
@@ -38,23 +38,26 @@ export interface FingerprintHeaders {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Generate a randomized device fingerprint.
|
|
41
|
-
* Each fingerprint represents a unique "device" identity.
|
|
41
|
+
* Each fingerprint represents a unique "device" identity. The userAgent is the
|
|
42
|
+
* shared Hub User-Agent because Cloud Code ties it to the release and build CL.
|
|
42
43
|
*/
|
|
43
44
|
export declare function generateFingerprint(): Fingerprint;
|
|
44
45
|
/**
|
|
45
46
|
* Collect fingerprint based on actual current system.
|
|
46
|
-
* Uses real OS info
|
|
47
|
+
* Uses real OS info for stored metadata; the userAgent is still the Hub User-Agent.
|
|
47
48
|
*/
|
|
48
49
|
export declare function collectCurrentFingerprint(): Fingerprint;
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
51
|
+
* Migrate a fingerprint's userAgent to the current Hub User-Agent.
|
|
52
|
+
* Saved fingerprints may carry a legacy `antigravity/<version> <os>/<arch>` agent or
|
|
53
|
+
* an older Hub release. Requests never send the stored value; this keeps storage in sync.
|
|
52
54
|
* Returns true if the userAgent was changed.
|
|
53
55
|
*/
|
|
54
56
|
export declare function updateFingerprintVersion(fingerprint: Fingerprint): boolean;
|
|
55
57
|
/**
|
|
56
58
|
* Build HTTP headers from a fingerprint object.
|
|
57
|
-
*
|
|
59
|
+
* The User-Agent is resolved at call time from the current Hub version, so a stale
|
|
60
|
+
* stored fingerprint userAgent is never sent.
|
|
58
61
|
*/
|
|
59
62
|
export declare function buildFingerprintHeaders(fingerprint: Fingerprint | null): Partial<FingerprintHeaders>;
|
|
60
63
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../../src/plugin/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../../src/plugin/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;CAChD;AAED,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;CACtB;AAkBD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,WAAW,CAajD;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,WAAW,CAavD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAQ1E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQpG;AAQD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,WAAW,CAKnD;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,WAAW,CAG1D"}
|
|
@@ -9,31 +9,23 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as crypto from "node:crypto";
|
|
11
11
|
import * as os from "node:os";
|
|
12
|
-
import {
|
|
13
|
-
const OS_VERSIONS = {
|
|
14
|
-
darwin: ["10.15.7", "11.6.8", "12.6.3", "13.5.2", "14.2.1", "14.5"],
|
|
15
|
-
win32: ["10.0.19041", "10.0.19042", "10.0.19043", "10.0.22000", "10.0.22621", "10.0.22631"],
|
|
16
|
-
linux: ["5.15.0", "5.19.0", "6.1.0", "6.2.0", "6.5.0", "6.6.0"],
|
|
17
|
-
};
|
|
18
|
-
const ARCHITECTURES = ["x64", "arm64"];
|
|
19
|
-
const IDE_TYPES = [
|
|
20
|
-
"ANTIGRAVITY",
|
|
21
|
-
];
|
|
22
|
-
const PLATFORMS = [
|
|
23
|
-
"WINDOWS",
|
|
24
|
-
"MACOS",
|
|
25
|
-
];
|
|
12
|
+
import { getAntigravityUserAgent } from "../constants.js";
|
|
26
13
|
const SDK_CLIENTS = [
|
|
27
14
|
"google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
28
15
|
"google-cloud-sdk vscode/1.86.0",
|
|
29
16
|
"google-cloud-sdk vscode/1.87.0",
|
|
30
17
|
"google-cloud-sdk vscode/1.96.0",
|
|
31
18
|
];
|
|
19
|
+
/** Matches the Hub User-Agent, which always reports the darwin/arm64 manifest build. */
|
|
20
|
+
const HUB_METADATA_PLATFORM = "MACOS";
|
|
32
21
|
/** Maximum number of fingerprint versions to keep per account */
|
|
33
22
|
export const MAX_FINGERPRINT_HISTORY = 5;
|
|
34
23
|
function randomFrom(arr) {
|
|
35
24
|
return arr[Math.floor(Math.random() * arr.length)];
|
|
36
25
|
}
|
|
26
|
+
function platformToDisplayName(platform) {
|
|
27
|
+
return platform === "win32" ? "WINDOWS" : "MACOS";
|
|
28
|
+
}
|
|
37
29
|
function generateDeviceId() {
|
|
38
30
|
return crypto.randomUUID();
|
|
39
31
|
}
|
|
@@ -42,23 +34,18 @@ function generateSessionToken() {
|
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
36
|
* Generate a randomized device fingerprint.
|
|
45
|
-
* Each fingerprint represents a unique "device" identity.
|
|
37
|
+
* Each fingerprint represents a unique "device" identity. The userAgent is the
|
|
38
|
+
* shared Hub User-Agent because Cloud Code ties it to the release and build CL.
|
|
46
39
|
*/
|
|
47
40
|
export function generateFingerprint() {
|
|
48
|
-
const platform = randomFrom(["darwin", "win32"]);
|
|
49
|
-
const arch = randomFrom(ARCHITECTURES);
|
|
50
|
-
const osVersion = randomFrom(OS_VERSIONS[platform] ?? OS_VERSIONS.darwin);
|
|
51
|
-
const matchingPlatform = platform === "win32"
|
|
52
|
-
? "WINDOWS"
|
|
53
|
-
: "MACOS";
|
|
54
41
|
return {
|
|
55
42
|
deviceId: generateDeviceId(),
|
|
56
43
|
sessionToken: generateSessionToken(),
|
|
57
|
-
userAgent:
|
|
44
|
+
userAgent: getAntigravityUserAgent(),
|
|
58
45
|
apiClient: randomFrom(SDK_CLIENTS),
|
|
59
46
|
clientMetadata: {
|
|
60
|
-
ideType:
|
|
61
|
-
platform:
|
|
47
|
+
ideType: "ANTIGRAVITY",
|
|
48
|
+
platform: HUB_METADATA_PLATFORM,
|
|
62
49
|
pluginType: "GEMINI",
|
|
63
50
|
},
|
|
64
51
|
createdAt: Date.now(),
|
|
@@ -66,52 +53,47 @@ export function generateFingerprint() {
|
|
|
66
53
|
}
|
|
67
54
|
/**
|
|
68
55
|
* Collect fingerprint based on actual current system.
|
|
69
|
-
* Uses real OS info
|
|
56
|
+
* Uses real OS info for stored metadata; the userAgent is still the Hub User-Agent.
|
|
70
57
|
*/
|
|
71
58
|
export function collectCurrentFingerprint() {
|
|
72
|
-
const platform = os.platform();
|
|
73
|
-
const arch = os.arch();
|
|
74
|
-
const matchingPlatform = platform === "win32"
|
|
75
|
-
? "WINDOWS"
|
|
76
|
-
: "MACOS";
|
|
77
59
|
return {
|
|
78
60
|
deviceId: generateDeviceId(),
|
|
79
61
|
sessionToken: generateSessionToken(),
|
|
80
|
-
userAgent:
|
|
62
|
+
userAgent: getAntigravityUserAgent(),
|
|
81
63
|
apiClient: "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
82
64
|
clientMetadata: {
|
|
83
65
|
ideType: "ANTIGRAVITY",
|
|
84
|
-
platform:
|
|
66
|
+
platform: platformToDisplayName(os.platform()),
|
|
85
67
|
pluginType: "GEMINI",
|
|
86
68
|
},
|
|
87
69
|
createdAt: Date.now(),
|
|
88
70
|
};
|
|
89
71
|
}
|
|
90
72
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
73
|
+
* Migrate a fingerprint's userAgent to the current Hub User-Agent.
|
|
74
|
+
* Saved fingerprints may carry a legacy `antigravity/<version> <os>/<arch>` agent or
|
|
75
|
+
* an older Hub release. Requests never send the stored value; this keeps storage in sync.
|
|
93
76
|
* Returns true if the userAgent was changed.
|
|
94
77
|
*/
|
|
95
78
|
export function updateFingerprintVersion(fingerprint) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const match = fingerprint.userAgent.match(versionPattern);
|
|
99
|
-
if (!match || match[2] === currentVersion) {
|
|
79
|
+
const currentUserAgent = getAntigravityUserAgent();
|
|
80
|
+
if (fingerprint.userAgent === currentUserAgent) {
|
|
100
81
|
return false;
|
|
101
82
|
}
|
|
102
|
-
fingerprint.userAgent =
|
|
83
|
+
fingerprint.userAgent = currentUserAgent;
|
|
103
84
|
return true;
|
|
104
85
|
}
|
|
105
86
|
/**
|
|
106
87
|
* Build HTTP headers from a fingerprint object.
|
|
107
|
-
*
|
|
88
|
+
* The User-Agent is resolved at call time from the current Hub version, so a stale
|
|
89
|
+
* stored fingerprint userAgent is never sent.
|
|
108
90
|
*/
|
|
109
91
|
export function buildFingerprintHeaders(fingerprint) {
|
|
110
92
|
if (!fingerprint) {
|
|
111
93
|
return {};
|
|
112
94
|
}
|
|
113
95
|
return {
|
|
114
|
-
"User-Agent":
|
|
96
|
+
"User-Agent": getAntigravityUserAgent(),
|
|
115
97
|
};
|
|
116
98
|
}
|
|
117
99
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../../../src/plugin/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../../../src/plugin/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE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SAAS,EAAE,8CAA8C;QACzD,cAAc,EAAE;YACd,OAAO,EAAE,aAAa;YACtB,QAAQ,EAAE,qBAAqB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;YAC9C,UAAU,EAAE,QAAQ;SACrB;QACD,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAwB;IAC/D,MAAM,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IACnD,IAAI,WAAW,CAAC,SAAS,KAAK,gBAAgB,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,SAAS,GAAG,gBAAgB,CAAC;IACzC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,WAA+B;IACrE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,YAAY,EAAE,uBAAuB,EAAE;KACxC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,IAAI,kBAAkB,GAAuB,IAAI,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,kBAAkB,GAAG,mBAAmB,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B;IAC1C,kBAAkB,GAAG,mBAAmB,EAAE,CAAC;IAC3C,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - either sink can be enabled independently
|
|
8
8
|
* - OPENCODE_ANTIGRAVITY_CONSOLE_LOG=1 → console output (independent of debug flags)
|
|
9
9
|
*/
|
|
10
|
-
import type { PluginClient } from "./types";
|
|
10
|
+
import type { PluginClient } from "./types.js";
|
|
11
11
|
export interface Logger {
|
|
12
12
|
debug(message: string, extra?: Record<string, unknown>): void;
|
|
13
13
|
info(message: string, extra?: Record<string, unknown>): void;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - either sink can be enabled independently
|
|
8
8
|
* - OPENCODE_ANTIGRAVITY_CONSOLE_LOG=1 → console output (independent of debug flags)
|
|
9
9
|
*/
|
|
10
|
-
import { isDebugTuiEnabled } from "./debug";
|
|
11
|
-
import { isTruthyFlag, writeConsoleLog, } from "./logging-utils";
|
|
10
|
+
import { isDebugTuiEnabled } from "./debug.js";
|
|
11
|
+
import { isTruthyFlag, writeConsoleLog, } from "./logging-utils.js";
|
|
12
12
|
const ENV_CONSOLE_LOG = "OPENCODE_ANTIGRAVITY_CONSOLE_LOG";
|
|
13
13
|
let _client = null;
|
|
14
14
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OAuthAuthDetails, ProjectContextResult } from "./types";
|
|
1
|
+
import type { OAuthAuthDetails, ProjectContextResult } from "./types.js";
|
|
2
2
|
interface AntigravityUserTier {
|
|
3
3
|
id?: string;
|
|
4
4
|
isDefault?: boolean;
|
|
@@ -18,11 +18,11 @@ interface LoadCodeAssistPayload {
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function invalidateProjectContextCache(refresh?: string): void;
|
|
20
20
|
/**
|
|
21
|
-
* Loads managed project information for the given access token
|
|
21
|
+
* Loads managed project information for the given access token from the Antigravity host.
|
|
22
22
|
*/
|
|
23
|
-
export declare function loadManagedProject(accessToken: string
|
|
23
|
+
export declare function loadManagedProject(accessToken: string): Promise<LoadCodeAssistPayload | null>;
|
|
24
24
|
/**
|
|
25
|
-
* Onboards a managed project for the user,
|
|
25
|
+
* Onboards a managed project for the user, polling until the operation completes.
|
|
26
26
|
*/
|
|
27
27
|
export declare function onboardManagedProject(accessToken: string, tierId: string, projectId?: string, attempts?: number, delayMs?: number): Promise<string | undefined>;
|
|
28
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/plugin/project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/plugin/project.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAmBtE,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C;AAED,UAAU,qBAAqB;IAC7B,uBAAuB,CAAC,EAAE,MAAM,GAAG;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,WAAW,CAAC,EAAE;QACZ,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,CAAC;IACF,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACtC;AA6ED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAQpE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CA0BnG;AAGD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,SAAK,EACb,OAAO,SAAO,GACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4C7B;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA+FhG"}
|
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatRefreshParts, parseRefreshParts } from "./auth";
|
|
3
|
-
import { createLogger } from "./logger";
|
|
1
|
+
import { ANTIGRAVITY_DEFAULT_PROJECT_ID, ANTIGRAVITY_ENDPOINT, ANTIGRAVITY_GOOG_API_CLIENT, getAntigravityOnboardUserAgent, getAntigravityUserAgent, getAntigravityVersion, } from "../constants.js";
|
|
2
|
+
import { formatRefreshParts, parseRefreshParts } from "./auth.js";
|
|
3
|
+
import { createLogger } from "./logger.js";
|
|
4
4
|
const log = createLogger("project");
|
|
5
5
|
const projectContextResultCache = new Map();
|
|
6
6
|
const projectContextPendingCache = new Map();
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const LOAD_TIMEOUT_MS = 10000;
|
|
8
|
+
const ONBOARD_TIMEOUT_MS = 30000;
|
|
9
|
+
/** Tier used for onboarding when loadCodeAssist does not advertise one. */
|
|
10
|
+
const DEFAULT_TIER_ID = "free-tier";
|
|
11
|
+
/**
|
|
12
|
+
* loadCodeAssist metadata sent by the Antigravity Hub. Platform and plugin type are
|
|
13
|
+
* omitted: MACOS/WINDOWS are not valid Cloud Code platform values.
|
|
14
|
+
*/
|
|
15
|
+
const LOAD_CODE_ASSIST_METADATA = { ideType: "ANTIGRAVITY" };
|
|
16
|
+
/**
|
|
17
|
+
* onboardUser metadata uses the snake_case control-plane fields and the Hub version.
|
|
18
|
+
*/
|
|
19
|
+
function buildOnboardMetadata() {
|
|
20
|
+
return {
|
|
21
|
+
ide_type: "ANTIGRAVITY",
|
|
22
|
+
ide_version: getAntigravityVersion(),
|
|
23
|
+
ide_name: "antigravity",
|
|
17
24
|
};
|
|
18
|
-
if (projectId) {
|
|
19
|
-
metadata.duetProject = projectId;
|
|
20
|
-
}
|
|
21
|
-
return metadata;
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
|
-
* Selects the
|
|
27
|
+
* Selects the tier to onboard with: the default allowed tier, then the first allowed
|
|
28
|
+
* tier, then the current tier, then free-tier.
|
|
25
29
|
*/
|
|
26
|
-
function getDefaultTierId(
|
|
27
|
-
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
+
function getDefaultTierId(payload) {
|
|
31
|
+
const allowedTiers = payload?.allowedTiers ?? [];
|
|
30
32
|
for (const tier of allowedTiers) {
|
|
31
|
-
if (tier?.isDefault) {
|
|
33
|
+
if (tier?.isDefault && tier.id) {
|
|
32
34
|
return tier.id;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
return allowedTiers[0]?.id;
|
|
37
|
+
return allowedTiers[0]?.id || payload?.currentTier?.id || DEFAULT_TIER_ID;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Promise-based delay utility.
|
|
@@ -42,20 +44,29 @@ function wait(ms) {
|
|
|
42
44
|
setTimeout(resolve, ms);
|
|
43
45
|
});
|
|
44
46
|
}
|
|
47
|
+
async function fetchWithTimeout(url, options, timeoutMs) {
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
50
|
+
try {
|
|
51
|
+
return await fetch(url, { ...options, signal: controller.signal });
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
clearTimeout(timeout);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extracts a cloudaicompanion project id from its string or `{ id }` form.
|
|
59
|
+
*/
|
|
60
|
+
function extractProjectId(value) {
|
|
61
|
+
const id = typeof value === "string" ? value : value?.id;
|
|
62
|
+
const trimmed = typeof id === "string" ? id.trim() : "";
|
|
63
|
+
return trimmed || undefined;
|
|
64
|
+
}
|
|
45
65
|
/**
|
|
46
66
|
* Extracts the cloudaicompanion project id from loadCodeAssist responses.
|
|
47
67
|
*/
|
|
48
68
|
function extractManagedProjectId(payload) {
|
|
49
|
-
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
if (typeof payload.cloudaicompanionProject === "string") {
|
|
53
|
-
return payload.cloudaicompanionProject;
|
|
54
|
-
}
|
|
55
|
-
if (payload.cloudaicompanionProject && typeof payload.cloudaicompanionProject.id === "string") {
|
|
56
|
-
return payload.cloudaicompanionProject.id;
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
69
|
+
return payload ? extractProjectId(payload.cloudaicompanionProject) : undefined;
|
|
59
70
|
}
|
|
60
71
|
/**
|
|
61
72
|
* Generates a cache key for project context based on refresh token.
|
|
@@ -77,75 +88,65 @@ export function invalidateProjectContextCache(refresh) {
|
|
|
77
88
|
projectContextResultCache.delete(refresh);
|
|
78
89
|
}
|
|
79
90
|
/**
|
|
80
|
-
* Loads managed project information for the given access token
|
|
91
|
+
* Loads managed project information for the given access token from the Antigravity host.
|
|
81
92
|
*/
|
|
82
|
-
export async function loadManagedProject(accessToken
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
method: "POST",
|
|
97
|
-
headers: loadHeaders,
|
|
98
|
-
body: JSON.stringify(requestBody),
|
|
99
|
-
});
|
|
100
|
-
if (!response.ok) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
return (await response.json());
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
log.debug("Failed to load managed project", { endpoint: baseEndpoint, error: String(error) });
|
|
107
|
-
continue;
|
|
93
|
+
export async function loadManagedProject(accessToken) {
|
|
94
|
+
try {
|
|
95
|
+
const response = await fetchWithTimeout(`${ANTIGRAVITY_ENDPOINT}/v1internal:loadCodeAssist`, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
Authorization: `Bearer ${accessToken}`,
|
|
100
|
+
"User-Agent": getAntigravityUserAgent(),
|
|
101
|
+
},
|
|
102
|
+
body: JSON.stringify({ metadata: LOAD_CODE_ASSIST_METADATA }),
|
|
103
|
+
}, LOAD_TIMEOUT_MS);
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
log.debug("loadCodeAssist failed", { endpoint: ANTIGRAVITY_ENDPOINT, status: response.status });
|
|
106
|
+
return null;
|
|
108
107
|
}
|
|
108
|
+
return (await response.json());
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
log.debug("Failed to load managed project", { endpoint: ANTIGRAVITY_ENDPOINT, error: String(error) });
|
|
112
|
+
return null;
|
|
109
113
|
}
|
|
110
|
-
return null;
|
|
111
114
|
}
|
|
112
115
|
/**
|
|
113
|
-
* Onboards a managed project for the user,
|
|
116
|
+
* Onboards a managed project for the user, polling until the operation completes.
|
|
114
117
|
*/
|
|
115
118
|
export async function onboardManagedProject(accessToken, tierId, projectId, attempts = 10, delayMs = 5000) {
|
|
116
|
-
const metadata = buildMetadata(projectId);
|
|
117
119
|
const requestBody = {
|
|
118
|
-
tierId,
|
|
119
|
-
metadata,
|
|
120
|
+
tier_id: tierId,
|
|
121
|
+
metadata: buildOnboardMetadata(),
|
|
120
122
|
};
|
|
121
|
-
for (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const managedProjectId = payload.response?.cloudaicompanionProject?.id;
|
|
138
|
-
if (payload.done && managedProjectId) {
|
|
139
|
-
return managedProjectId;
|
|
140
|
-
}
|
|
141
|
-
if (payload.done && projectId) {
|
|
142
|
-
return projectId;
|
|
143
|
-
}
|
|
123
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetchWithTimeout(`${ANTIGRAVITY_ENDPOINT}/v1internal:onboardUser`, {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
Accept: "*/*",
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
Authorization: `Bearer ${accessToken}`,
|
|
131
|
+
"User-Agent": getAntigravityOnboardUserAgent(),
|
|
132
|
+
"X-Goog-Api-Client": ANTIGRAVITY_GOOG_API_CLIENT,
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify(requestBody),
|
|
135
|
+
}, ONBOARD_TIMEOUT_MS);
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
log.debug("onboardUser failed", { endpoint: ANTIGRAVITY_ENDPOINT, status: response.status });
|
|
138
|
+
return undefined;
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
const payload = (await response.json());
|
|
141
|
+
if (payload.done) {
|
|
142
|
+
return extractProjectId(payload.response?.cloudaicompanionProject) ?? projectId;
|
|
148
143
|
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
log.debug("Failed to onboard managed project", { endpoint: ANTIGRAVITY_ENDPOINT, error: String(error) });
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
if (attempt < attempts - 1) {
|
|
149
150
|
await wait(delayMs);
|
|
150
151
|
}
|
|
151
152
|
}
|
|
@@ -188,14 +189,14 @@ export async function ensureProjectContext(auth) {
|
|
|
188
189
|
return { auth: updatedAuth, effectiveProjectId: managedProjectId };
|
|
189
190
|
};
|
|
190
191
|
// Try to resolve a managed project from Antigravity if possible.
|
|
191
|
-
const loadPayload = await loadManagedProject(accessToken
|
|
192
|
+
const loadPayload = await loadManagedProject(accessToken);
|
|
192
193
|
const resolvedManagedProjectId = extractManagedProjectId(loadPayload);
|
|
193
194
|
if (resolvedManagedProjectId) {
|
|
194
195
|
return persistManagedProject(resolvedManagedProjectId);
|
|
195
196
|
}
|
|
196
197
|
// No managed project found - try to auto-provision one via onboarding.
|
|
197
198
|
// This handles accounts that were added before managed project provisioning was required.
|
|
198
|
-
const tierId = getDefaultTierId(loadPayload
|
|
199
|
+
const tierId = getDefaultTierId(loadPayload);
|
|
199
200
|
log.debug("Auto-provisioning managed project", { tierId, projectId: parts.projectId });
|
|
200
201
|
const provisionedProjectId = await onboardManagedProject(accessToken, tierId, parts.projectId);
|
|
201
202
|
if (provisionedProjectId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/plugin/project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/plugin/project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC3B,8BAA8B,EAC9B,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,MAAM,GAAG,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;AAEpC,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAgC,CAAC;AAC1E,MAAM,0BAA0B,GAAG,IAAI,GAAG,EAAyC,CAAC;AAEpF,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC;;;GAGG;AACH,MAAM,yBAAyB,GAAG,EAAE,OAAO,EAAE,aAAa,EAAW,CAAC;AAuBtE;;GAEG;AACH,SAAS,oBAAoB;IAC3B,OAAO;QACL,QAAQ,EAAE,aAAa;QACvB,WAAW,EAAE,qBAAqB,EAAE;QACpC,QAAQ,EAAE,aAAa;KACxB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAqC;IAC7D,MAAM,YAAY,GAAG,O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V3 } from "./storage";
|
|
1
|
+
import type { PluginClient } from "./types.js";
|
|
2
|
+
import type { AccountMetadataV3 } from "./storage.js";
|
|
3
3
|
export type QuotaGroup = "claude" | "gemini-pro" | "gemini-flash";
|
|
4
4
|
export interface QuotaGroupSummary {
|
|
5
5
|
remainingFraction?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quota.d.ts","sourceRoot":"","sources":["../../../src/plugin/quota.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quota.d.ts","sourceRoot":"","sources":["../../../src/plugin/quota.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAInD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,cAAc,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAYD,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC;AAE7D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC;AA2PD,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,MAAM,EAAE,YAAY,EACpB,UAAU,SAA0B,GACnC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiF/B"}
|
package/dist/src/plugin/quota.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ANTIGRAVITY_ENDPOINT_PROD,
|
|
2
|
-
import { accessTokenExpired, formatRefreshParts, parseRefreshParts } from "./auth";
|
|
3
|
-
import { logQuotaFetch, logQuotaStatus } from "./debug";
|
|
4
|
-
import { ensureProjectContext } from "./project";
|
|
5
|
-
import { refreshAccessToken } from "./token";
|
|
6
|
-
import { getModelFamily } from "./transform/model-resolver";
|
|
1
|
+
import { ANTIGRAVITY_ENDPOINT, ANTIGRAVITY_ENDPOINT_PROD, getAntigravityUserAgent, ANTIGRAVITY_PROVIDER_ID, } from "../constants.js";
|
|
2
|
+
import { accessTokenExpired, formatRefreshParts, parseRefreshParts } from "./auth.js";
|
|
3
|
+
import { logQuotaFetch, logQuotaStatus } from "./debug.js";
|
|
4
|
+
import { ensureProjectContext } from "./project.js";
|
|
5
|
+
import { refreshAccessToken } from "./token.js";
|
|
6
|
+
import { getModelFamily } from "./transform/model-resolver.js";
|
|
7
7
|
const FETCH_TIMEOUT_MS = 10000;
|
|
8
8
|
function buildAuthFromAccount(account) {
|
|
9
9
|
return {
|
|
@@ -56,6 +56,9 @@ function aggregateQuota(models) {
|
|
|
56
56
|
}
|
|
57
57
|
let totalCount = 0;
|
|
58
58
|
for (const [modelName, entry] of Object.entries(models)) {
|
|
59
|
+
if (!entry || typeof entry !== "object") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
59
62
|
const group = classifyQuotaGroup(modelName, entry.displayName ?? entry.modelName);
|
|
60
63
|
if (!group) {
|
|
61
64
|
continue;
|
|
@@ -105,8 +108,9 @@ async function fetchWithTimeout(url, options, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
async function fetchAvailableModels(accessToken, projectId) {
|
|
108
|
-
|
|
109
|
-
const
|
|
111
|
+
// Antigravity quota comes from the same host and Hub User-Agent as content requests.
|
|
112
|
+
const endpoint = ANTIGRAVITY_ENDPOINT;
|
|
113
|
+
const quotaUserAgent = getAntigravityUserAgent();
|
|
110
114
|
const errors = [];
|
|
111
115
|
const body = projectId ? { project: projectId } : {};
|
|
112
116
|
const response = await fetchWithTimeout(`${endpoint}/v1internal:fetchAvailableModels`, {
|