@heyhuynhgiabuu/pi-oauth-antigravity 0.1.8 → 0.2.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/CHANGELOG.md +67 -0
- package/README.md +37 -11
- package/dist/auth/oauth.js +1 -0
- package/dist/client/client.js +15 -4
- package/dist/diagnostics/diagnostics.d.ts +10 -0
- package/dist/diagnostics/diagnostics.js +12 -0
- package/dist/index.js +15 -4
- package/dist/models/models.d.ts +19 -16
- package/dist/models/models.js +108 -50
- package/dist/stream/stream.d.ts +7 -0
- package/dist/stream/stream.js +68 -12
- package/dist/types/types.d.ts +1 -0
- package/dist/usage/adapter.d.ts +18 -0
- package/dist/usage/adapter.js +271 -0
- package/dist/usage/index.d.ts +1 -0
- package/dist/usage/index.js +1 -0
- package/dist/usage/usage.d.ts +2 -2
- package/dist/usage/usage.js +26 -2
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,73 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-11-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Gemini 4 Carbon** (`gemini-4-carbon-{low,medium,high}`, launched 2026-11-10) and
|
|
15
|
+
**Gemini 4 Hydrogen** (`gemini-4-hydrogen-{low,medium,high,xhigh}`, launched 2026-11-12 —
|
|
16
|
+
the backend's first `-xhigh` effort tier). Carbon/Hydrogen wire ids follow the family
|
|
17
|
+
pattern and are UNVERIFIED against a live listing; rejected requests fall back through
|
|
18
|
+
the Gemini 4 family (Hydrogen → Carbon → Argon → 3.8 Flash), with an xHigh tier
|
|
19
|
+
downgrade at each family boundary since only Hydrogen advertises `-xhigh`.
|
|
20
|
+
- Fresh `x-cloudaicompanion-trace-id` / `X-Aicode-Request-Id` headers on every request.
|
|
21
|
+
- **403 `TOS_VIOLATION` is recognized and surfaces account-risk advice** instead of the
|
|
22
|
+
generic "try another model, re-login" line. Google is actively enforcing third-party
|
|
23
|
+
OAuth use (the appeal copy names "third party software"); the reason lives in
|
|
24
|
+
`error.details`, which the old message path dropped, so a flagged account now gets told
|
|
25
|
+
that retries and re-login will not clear it and that further use risks suspension.
|
|
26
|
+
- **Server `Retry-After` is honored on transient 429s** (seconds or HTTP-date form,
|
|
27
|
+
capped at 60s). A longer `Retry-After` is a cooldown that cannot clear inside the
|
|
28
|
+
retry loop (CPA issue #6646), so no attempts are burned on it and the backend's own
|
|
29
|
+
reset note is surfaced. Without the header the 2s/4s backoff is unchanged.
|
|
30
|
+
- Claude Opus 5.5 / Sonnet 5.5 are documented as officially served (2026-11 models doc,
|
|
31
|
+
live discovery since 2026-10-03); the listed output/context figures remain same-family
|
|
32
|
+
estimates until Google publishes 5.5-specific numbers.
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- **Gemini 4 Carbon** (`gemini-4-carbon-{low,medium,high}`, launched 2026-11-10) and
|
|
37
|
+
**Gemini 4 Hydrogen** (`gemini-4-hydrogen-{low,medium,high,xhigh}`, launched 2026-11-12 —
|
|
38
|
+
the backend's first `-xhigh` effort tier). Carbon/Hydrogen wire ids follow the family
|
|
39
|
+
pattern and are UNVERIFIED against a live listing; rejected requests fall back through
|
|
40
|
+
the Gemini 4 family (Hydrogen → Carbon → Argon → 3.8 Flash), with an xHigh tier
|
|
41
|
+
downgrade at each family boundary since only Hydrogen advertises `-xhigh`.
|
|
42
|
+
- Fresh `x-cloudaicompanion-trace-id` / `X-Aicode-Request-Id` headers on every request.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- **`claude-opus-4-6-thinking`, `claude-sonnet-4-6` and `gpt-oss-120b-medium` leave the
|
|
47
|
+
selectable catalog** — Google removes them on 2026-11-18. Pinned overrides to their wire
|
|
48
|
+
ids still resolve (routing + output-token entries retained), and the retirement-notice
|
|
49
|
+
detector now covers their plain-text notices instead of rendering them as assistant text;
|
|
50
|
+
the surfaced error names retirement generically and points at `/antigravity.models`.
|
|
51
|
+
- **Request identity tracks the shipping client** (`antigravity/hub/2.32.1`, was 2.23.0).
|
|
52
|
+
A stale identity silently receives a REDUCED model catalog from discovery, without an
|
|
53
|
+
error (codex2api e3d59f9; oh-my-pi pinned 2.32.1 on 2026-11-14 for the same reason).
|
|
54
|
+
- Gemini 4 Argon is no longer provisional: launched 2026-10-13, wire ids verified against
|
|
55
|
+
live `fetchAvailableModels` (opencodex 2026-10-14, codex2api 2026-10-16). Catalog table
|
|
56
|
+
and README reflect the 2026-11 models doc; README carries a ToS-risk warning for
|
|
57
|
+
third-party OAuth use.
|
|
58
|
+
|
|
59
|
+
## [0.1.9] - 2026-10-26
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
- Optional [`pi-usage-core`](https://github.com/ReStranger/pi-usage-core) integration. When that extension is loaded, Antigravity quota pools (Gemini 5h/weekly, Claude+GPT) and account details are also registered into its unified `/usage` dashboard and persistent footer status line. `pi-usage-core` is not a runtime dependency: with or without it, this package works on its own.
|
|
63
|
+
- `/antigravity.doctor` now reports which usage mode is active on a `usageCore=` line.
|
|
64
|
+
|
|
65
|
+
### Changed
|
|
66
|
+
- `/antigravity.usage` remains available as a standalone command and now appends a one-line tip when `pi-usage-core` is installed, instead of being replaced by the integration.
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
- A background quota poll no longer overwrites the diagnostics `/antigravity.doctor` reports. Quota reads run in a detached bag, so a failed usage fetch (e.g. free-tier `SUBSCRIPTION_REQUIRED`) is no longer shown as the last model request's error.
|
|
70
|
+
- A quota group whose buckets were all filtered out no longer produced a `ready` account with an empty pool, and no longer suppressed the per-model quota fallback.
|
|
71
|
+
- Bucket periods are mapped from the reported window instead of collapsing every non-5h bucket to `weekly`, so daily and monthly quotas are no longer mislabelled in the footer's multi-window format.
|
|
72
|
+
- Free-tier quota synthesized from the model catalog is labelled `total` instead of claiming a 5h session the backend never reported.
|
|
73
|
+
- Groups sharing a model family no longer produce duplicate pool ids.
|
|
74
|
+
- The account email is masked before it is displayed in a usage dashboard.
|
|
75
|
+
- The `auth.json` credential fallback now uses the host's `readStoredCredential`, and a stored token without an expiry is usable instead of being silently ignored.
|
|
76
|
+
|
|
10
77
|
## [0.1.8] - 2026-10-15
|
|
11
78
|
|
|
12
79
|
### Fixed
|
package/README.md
CHANGED
|
@@ -14,33 +14,57 @@ Google Antigravity OAuth provider extension for [Pi](https://pi.dev). Connects P
|
|
|
14
14
|
- Cross-restart session state persistence (`.pi/agent/cache/antigravity-sessions.json`) to maintain cluster affinity across quick Pi restarts.
|
|
15
15
|
- **Image Generation**: Built-in `generate_image` tool and `/antigravity.image` command powered by Google's image models with aspect-ratio selection and safe directory containment.
|
|
16
16
|
- **Diagnostic & Usage Tools**:
|
|
17
|
-
- `/antigravity.usage` —
|
|
18
|
-
-
|
|
17
|
+
- `/antigravity.usage` — shared quota pools (Gemini 5h/weekly, Claude+GPT 5h) with plan tier and reset countdowns.
|
|
18
|
+
- Optional unified dashboard: install [`pi-usage-core`](https://github.com/ReStranger/pi-usage-core) and the same pools also appear in the shared `/usage` dashboard and footer status line.
|
|
19
|
+
- `/antigravity.models` — backend discovery of available Cloud Code Assist models and remaining pool fractions.
|
|
19
20
|
- `/antigravity.doctor` — connection check, token expiry inspection, and diagnostic dump.
|
|
20
21
|
|
|
21
22
|
## Supported Models
|
|
22
23
|
|
|
23
24
|
| Public Model ID | Backend Wire ID | Max Output | Context Window |
|
|
24
25
|
| :--- | :--- | :--- | :--- |
|
|
25
|
-
| `antigravity/gemini-4-
|
|
26
|
+
| `antigravity/gemini-4-hydrogen` | `gemini-4-hydrogen-{low,medium,high,xhigh}`† | 65,536† | 1,048,576† |
|
|
27
|
+
| `antigravity/gemini-4-carbon` | `gemini-4-carbon-{low,medium,high}`† | 65,536† | 1,048,576† |
|
|
28
|
+
| `antigravity/gemini-4-argon` | `gemini-4-argon-{low,medium,high}` | 65,536† | 1,048,576† |
|
|
26
29
|
| `antigravity/gemini-3.8-flash` | `gemini-3.8-flash-{low,medium,high}` | 65,536 | 1,048,576 |
|
|
27
30
|
| `antigravity/gemini-3.7-flash` | `gemini-3.7-flash-{low,medium,high}` | 65,536 | 1,048,576 |
|
|
28
31
|
| `antigravity/gemini-3.7-flash-thinking` | `gemini-3.7-flash-thinking` | 65,536 | 1,048,576 |
|
|
29
32
|
| `antigravity/gemini-3.6-flash` | `gemini-3.6-flash-{low,medium,high}` | 65,536 | 1,048,576 |
|
|
30
33
|
| `antigravity/gemini-3.1-pro` | `gemini-3.1-pro` | 65,536 | 1,048,576 |
|
|
31
|
-
| `antigravity/claude-opus-4-6` | `claude-opus-4-6` | 64,000 | 200,000 |
|
|
32
34
|
| `antigravity/claude-opus-5-5-low` | `claude-opus-5-5-low` | 64,000* | 250,000* |
|
|
33
35
|
| `antigravity/claude-opus-5-5-medium` | `claude-opus-5-5-medium` | 64,000* | 250,000* |
|
|
34
36
|
| `antigravity/claude-opus-5-5-high` | `claude-opus-5-5-high` | 64,000* | 250,000* |
|
|
35
|
-
| `antigravity/claude-sonnet-4-6` | `claude-sonnet-4-6` | 64,000 | 200,000 |
|
|
36
37
|
| `antigravity/claude-sonnet-5-5-low` | `claude-sonnet-5-5-low` | 64,000* | 200,000* |
|
|
37
38
|
| `antigravity/claude-sonnet-5-5-medium` | `claude-sonnet-5-5-medium` | 64,000* | 200,000* |
|
|
38
39
|
| `antigravity/claude-sonnet-5-5-high` | `claude-sonnet-5-5-high` | 64,000* | 200,000* |
|
|
39
|
-
| `antigravity/gpt-oss-120b` | `gpt-oss-120b` | 8,192 | 131,072 |
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Hydrogen (2026-11-12) is the first model with an `-xhigh` effort tier; Carbon (2026-11-10)
|
|
42
|
+
and Argon (2026-10-13) top out at High. Argon/Carbon/Hydrogen are entitlement-gated
|
|
43
|
+
(Ultra / Enterprise / paid Pro); a rejected request falls back through the Gemini 4
|
|
44
|
+
family to Gemini 3.8 Flash.
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
`claude-opus-4-6-thinking`, `claude-sonnet-4-6` and `gpt-oss-120b-medium` were removed by
|
|
47
|
+
Google on **2026-11-18** and are no longer selectable; pinned overrides to their wire ids
|
|
48
|
+
still resolve until the backend drops them, and their retirement notices are detected and
|
|
49
|
+
surfaced as errors instead of assistant text.
|
|
50
|
+
|
|
51
|
+
### Third-party OAuth is a ToS risk
|
|
52
|
+
|
|
53
|
+
Google's enforcement against third-party Antigravity OAuth clients is active: appeal forms
|
|
54
|
+
name "using third party software to access Antigravity", and 403 `PERMISSION_DENIED /
|
|
55
|
+
TOS_VIOLATION` reports against third-party clients exist (oh-my-pi paused its provider on
|
|
56
|
+
2026-11-14 for this reason). Using this extension may put your Google account at risk —
|
|
57
|
+
prefer the official Antigravity IDE/CLI when possible, and don't say you weren't warned.
|
|
58
|
+
|
|
59
|
+
† Gemini 4 family: Argon wire ids verified against live discovery (2026-10-14); Carbon/Hydrogen wire ids follow the family pattern but are UNVERIFIED against a live listing. Limits and pricing are same-family estimates; a rejected request falls back to the previous Gemini 4 model, then Gemini 3.8 Flash.
|
|
60
|
+
|
|
61
|
+
\* Claude Opus 5.5 / Sonnet 5.5 are officially served (2026-11 models doc, live discovery
|
|
62
|
+
since 2026-10-03); the listed output/context figures stay same-family estimates until
|
|
63
|
+
Google publishes 5.5-specific numbers.
|
|
64
|
+
|
|
65
|
+
The request identity tracks the shipping client (`antigravity/hub/2.32.1`) and every call
|
|
66
|
+
sends fresh `x-cloudaicompanion-trace-id` / `X-Aicode-Request-Id` headers — a stale client
|
|
67
|
+
identity silently receives a REDUCED model catalog from discovery, without an error.
|
|
44
68
|
|
|
45
69
|
## Installation
|
|
46
70
|
|
|
@@ -71,18 +95,20 @@ pi -e /path/to/pi-oauth-antigravity/dist/index.js
|
|
|
71
95
|
|
|
72
96
|
## Slash Commands
|
|
73
97
|
|
|
74
|
-
- `/antigravity.usage` — View
|
|
75
|
-
- `/antigravity.models` — List dynamically fetched and statically registered models.
|
|
98
|
+
- `/antigravity.usage` — View shared quota pools (Gemini 5h/weekly, Claude+GPT 5h), plan tier, and reset countdowns.
|
|
99
|
+
- `/antigravity.models` — List dynamically fetched and statically registered models + remaining pool fraction.
|
|
76
100
|
- `/antigravity.doctor` — Diagnose OAuth state, refresh token health, and endpoint connectivity.
|
|
77
101
|
- `/antigravity.image <prompt> [--aspect 1:1|16:9|...]` — Generate images directly to your project.
|
|
78
102
|
|
|
103
|
+
> **Optional: unified `/usage` dashboard.** This extension always works standalone. If you also install [`pi-usage-core`](https://github.com/ReStranger/pi-usage-core) (`pi install npm:pi-usage-core`), the Antigravity pools are additionally registered into its interactive `/usage` dashboard and persistent footer status line. `/antigravity.doctor` reports which mode is active on the `usageCore=` line.
|
|
104
|
+
|
|
79
105
|
## Development
|
|
80
106
|
|
|
81
107
|
```bash
|
|
82
108
|
# Install dependencies
|
|
83
109
|
npm install
|
|
84
110
|
|
|
85
|
-
# Run unit tests (
|
|
111
|
+
# Run unit tests (84 tests)
|
|
86
112
|
npm test
|
|
87
113
|
|
|
88
114
|
# Typecheck
|
package/dist/auth/oauth.js
CHANGED
package/dist/client/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { Platform } from "../types/enums.js";
|
|
3
3
|
import { getCurrentAvailableModels, getCurrentEndpoint, getCurrentMatchedModelDebug, setLastAvailableModels, setLastEndpoint, setLastError, setLastMatchedModelDebug, setLastStatus, } from "../diagnostics/diagnostics.js";
|
|
4
4
|
import { assertSafeApiBaseUrl, safeError } from "../utils/security.js";
|
|
@@ -45,8 +45,11 @@ export function endpointCandidates(preferredEndpoint) {
|
|
|
45
45
|
}
|
|
46
46
|
return ENDPOINT_FALLBACKS;
|
|
47
47
|
}
|
|
48
|
-
// Cloud Code rejects newer models (e.g. Gemini 4 Argon) for clients below 2.23.0
|
|
49
|
-
|
|
48
|
+
// Cloud Code rejects newer models (e.g. Gemini 4 Argon) for clients below 2.23.0, and a
|
|
49
|
+
// stale identity silently gets a REDUCED catalog from discovery (no error): control-plane
|
|
50
|
+
// requests sent as antigravity/1.11.3 returned fewer models (codex2api e3d59f9). Track the
|
|
51
|
+
// shipping client — oh-my-pi pinned 2.32.1 on 2026-11-14 for the same reason.
|
|
52
|
+
const DEFAULT_ANTIGRAVITY_VERSION = "2.32.1";
|
|
50
53
|
const DEFAULT_ANTIGRAVITY_CL = "963137146";
|
|
51
54
|
function defaultUserAgent() {
|
|
52
55
|
const version = antigravityEnv("HUB_VERSION") || DEFAULT_ANTIGRAVITY_VERSION;
|
|
@@ -67,6 +70,10 @@ export function antigravityHeaders(token) {
|
|
|
67
70
|
Accept: "text/event-stream",
|
|
68
71
|
"User-Agent": antigravityEnv("USER_AGENT") || defaultUserAgent(),
|
|
69
72
|
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
73
|
+
// Per-request trace/request ids match the shipping client (oh-my-pi #19279,
|
|
74
|
+
// 2026-11-14): requests without them were served the reduced catalog.
|
|
75
|
+
"x-cloudaicompanion-trace-id": randomUUID(),
|
|
76
|
+
"X-Aicode-Request-Id": randomUUID(),
|
|
70
77
|
"Client-Metadata": JSON.stringify({
|
|
71
78
|
ideType: "ANTIGRAVITY",
|
|
72
79
|
platform,
|
|
@@ -93,7 +100,11 @@ export function parseApiKey(apiKeyRaw) {
|
|
|
93
100
|
const parsed = JSON.parse(apiKeyRaw);
|
|
94
101
|
if (!parsed.token || !parsed.projectId)
|
|
95
102
|
throw new Error("missing token or projectId");
|
|
96
|
-
return {
|
|
103
|
+
return {
|
|
104
|
+
token: parsed.token,
|
|
105
|
+
projectId: parsed.projectId,
|
|
106
|
+
...(parsed.email ? { email: parsed.email } : {}),
|
|
107
|
+
};
|
|
97
108
|
}
|
|
98
109
|
catch (error) {
|
|
99
110
|
throw new Error(`Invalid Antigravity credentials. Run /login antigravity. (${safeError(error)})`, { cause: error });
|
|
@@ -12,6 +12,16 @@ export type DiagnosticsSnapshot = {
|
|
|
12
12
|
};
|
|
13
13
|
/** Run work with an isolated diagnostics bag; commits it to `lastSnapshot` when done. */
|
|
14
14
|
export declare function runWithDiagnostics<T>(fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Run work with its own diagnostics bag that is discarded instead of committed.
|
|
17
|
+
*
|
|
18
|
+
* `/antigravity.doctor` reports the snapshot of the last model request, so a read-only poll
|
|
19
|
+
* must not commit: a quota fetch that fails for unrelated reasons (e.g. the free-tier
|
|
20
|
+
* `SUBSCRIPTION_REQUIRED` RPC) would otherwise be shown as that request's error. Used by the
|
|
21
|
+
* usage adapter's background polling and by the `/antigravity.usage` / `/antigravity.models`
|
|
22
|
+
* commands.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runWithDetachedDiagnostics<T>(fn: () => Promise<T>): Promise<T>;
|
|
15
25
|
export declare function getLastDiagnostics(): Readonly<DiagnosticsSnapshot>;
|
|
16
26
|
/** Read endpoint from the active request bag (or last snapshot outside a request). */
|
|
17
27
|
export declare function getCurrentEndpoint(): string | undefined;
|
|
@@ -18,6 +18,18 @@ export async function runWithDiagnostics(fn) {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Run work with its own diagnostics bag that is discarded instead of committed.
|
|
23
|
+
*
|
|
24
|
+
* `/antigravity.doctor` reports the snapshot of the last model request, so a read-only poll
|
|
25
|
+
* must not commit: a quota fetch that fails for unrelated reasons (e.g. the free-tier
|
|
26
|
+
* `SUBSCRIPTION_REQUIRED` RPC) would otherwise be shown as that request's error. Used by the
|
|
27
|
+
* usage adapter's background polling and by the `/antigravity.usage` / `/antigravity.models`
|
|
28
|
+
* commands.
|
|
29
|
+
*/
|
|
30
|
+
export async function runWithDetachedDiagnostics(fn) {
|
|
31
|
+
return storage.run({}, fn);
|
|
32
|
+
}
|
|
21
33
|
export function getLastDiagnostics() {
|
|
22
34
|
return lastSnapshot;
|
|
23
35
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { StringEnum, Type } from "@earendil-works/pi-ai";
|
|
|
2
2
|
import { registerApiProvider } from "@earendil-works/pi-ai/compat";
|
|
3
3
|
import { getApiKey, loginAntigravity, refreshAntigravityToken } from "./auth/index.js";
|
|
4
4
|
import { DEFAULT_ENDPOINT, endpointCandidates } from "./client/index.js";
|
|
5
|
-
import { getLastDiagnostics,
|
|
5
|
+
import { getLastDiagnostics, runWithDetachedDiagnostics } from "./diagnostics/index.js";
|
|
6
6
|
import { DEFAULT_IMAGE_MODEL, generateAntigravityImage, IMAGE_ASPECT_RATIOS, parseImageCommandArgs, } from "./image/index.js";
|
|
7
7
|
import { ANTIGRAVITY_MODELS, PROVIDER_ID, PROVIDER_NAME } from "./models/index.js";
|
|
8
8
|
import { ANTIGRAVITY_API, streamAntigravity } from "./stream/index.js";
|
|
9
|
-
import { fetchAccountUsage, formatModelsList, formatUsageSummary, resolveApiKeyFromContext, } from "./usage/index.js";
|
|
9
|
+
import { fetchAccountUsage, formatModelsList, formatUsageSummary, isUsageCoreAvailable, registerAntigravityUsageAdapter, resolveApiKeyFromContext, } from "./usage/index.js";
|
|
10
10
|
import { prewarmConnection, redactSecrets } from "./utils/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* Pi's interactive `notify` writes into the chat transcript. `console.log` in that
|
|
@@ -31,7 +31,9 @@ async function withUsage(ctx, fn) {
|
|
|
31
31
|
}
|
|
32
32
|
if (ctx.hasUI)
|
|
33
33
|
ctx.ui.notify("Fetching Antigravity usage…", "info");
|
|
34
|
-
|
|
34
|
+
// Detached: /antigravity.usage and /antigravity.models read quota state, they are not model
|
|
35
|
+
// requests. Committing their poll would make doctor report a quota-RPC error as lastError.
|
|
36
|
+
const usage = await runWithDetachedDiagnostics(() => fetchAccountUsage(apiKey));
|
|
35
37
|
emitCommandOutput(ctx, fn(usage));
|
|
36
38
|
}
|
|
37
39
|
catch (error) {
|
|
@@ -63,10 +65,18 @@ export default function (pi) {
|
|
|
63
65
|
},
|
|
64
66
|
streamSimple: streamAntigravity,
|
|
65
67
|
});
|
|
68
|
+
registerAntigravityUsageAdapter(pi);
|
|
66
69
|
pi.registerCommand("antigravity.usage", {
|
|
67
70
|
description: "Show Antigravity shared quota pools (Gemini / Claude+GPT, 5h + weekly)",
|
|
68
71
|
handler: async (_args, ctx) => {
|
|
69
|
-
|
|
72
|
+
// Keep this command working on its own: `pi-usage-core` is an optional third-party
|
|
73
|
+
// extension, so a user who has not installed it has no other way to read quotas.
|
|
74
|
+
await withUsage(ctx, (usage) => {
|
|
75
|
+
const summary = formatUsageSummary(usage);
|
|
76
|
+
return isUsageCoreAvailable()
|
|
77
|
+
? `${summary}\n\nTip: pi-usage-core is installed — /usage shows these pools in the unified dashboard.`
|
|
78
|
+
: summary;
|
|
79
|
+
});
|
|
70
80
|
},
|
|
71
81
|
});
|
|
72
82
|
pi.registerCommand("antigravity.models", {
|
|
@@ -92,6 +102,7 @@ export default function (pi) {
|
|
|
92
102
|
`lastError=${d.error ? redactSecrets(d.error) : "none"}`,
|
|
93
103
|
"transport=native-streamSimple",
|
|
94
104
|
"runtimeCli=not-used",
|
|
105
|
+
`usageCore=${isUsageCoreAvailable() ? "registered" : "not-installed (install pi-usage-core for /usage)"}`,
|
|
95
106
|
"commands=/antigravity.usage /antigravity.models /antigravity.doctor /antigravity.image",
|
|
96
107
|
];
|
|
97
108
|
emitCommandOutput(ctx, `Antigravity doctor\n${lines.join("\n")}`);
|
package/dist/models/models.d.ts
CHANGED
|
@@ -5,27 +5,30 @@ export declare const PROVIDER_NAME = "Antigravity";
|
|
|
5
5
|
/**
|
|
6
6
|
* Public selectable model IDs → backend request model IDs by thinking effort.
|
|
7
7
|
*
|
|
8
|
-
* Catalog mirrors `agy models` (Antigravity CLI), which
|
|
9
|
-
* - Gemini 4 Argon (Low / Medium / High) —
|
|
8
|
+
* Catalog mirrors `agy models` (Antigravity CLI) and the 2026-11 models doc, which advertises:
|
|
9
|
+
* - Gemini 4 Argon (Low / Medium / High) — CONFIRMED: launched 2026-10-13; wire IDs
|
|
10
|
+
* `gemini-4-argon-{low,medium,high}` verified against live `fetchAvailableModels`
|
|
11
|
+
* (opencodex 2026-10-14, codex2api 2026-10-16). Entitlement-gated (Ultra / Enterprise /
|
|
12
|
+
* paid Pro); requests fall back to Gemini 3.8 Flash when the backend rejects it.
|
|
13
|
+
* - Gemini 4 Carbon (Low / Medium / High) — launched 2026-11-10 (changelog v2.31.0);
|
|
14
|
+
* CCA wire IDs follow the family pattern but are UNVERIFIED against a live listing,
|
|
15
|
+
* so requests fall back through Argon to Gemini 3.8 Flash when rejected.
|
|
16
|
+
* - Gemini 4 Hydrogen (Low / Medium / High / xHigh) — launched 2026-11-12; the four
|
|
17
|
+
* SKUs incl. the new `-xhigh` tier were observed in live discovery (oh-my-pi 7c74c203,
|
|
18
|
+
* opencodex #8644 2026-11-13). Falls back through Carbon → Argon → 3.8 Flash.
|
|
10
19
|
* - Gemini 3.8 Flash (Low / Medium / High)
|
|
11
|
-
* - Gemini 3.7 Flash (Low / Medium / High)
|
|
12
|
-
*
|
|
20
|
+
* - Gemini 3.7 Flash (Low / Medium / High) — still served, single `gemini-3.7-flash-tiered`
|
|
21
|
+
* wire id on newer discovery payloads; Enterprise-only per the 2026-11 models doc.
|
|
22
|
+
* - Gemini 3.6 Flash (Low / Medium / High) — Enterprise-only; effectively absent from CCA
|
|
23
|
+
* for non-Enterprise accounts since 3.7 shipped, but kept selectable for entitled ones.
|
|
13
24
|
* - Gemini 3.1 Pro (Low / High)
|
|
14
|
-
* - Claude Sonnet 4.6 (Thinking)
|
|
15
|
-
* - Claude Opus 4.6 (Thinking)
|
|
16
25
|
* - Claude Opus 5.5 (Low / Medium / High)
|
|
17
26
|
* - Claude Sonnet 5.5 (Low / Medium / High)
|
|
18
|
-
* - GPT-OSS 120B (Medium)
|
|
19
27
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Gemini 3.5 Flash is intentionally omitted from the selectable catalog; the
|
|
26
|
-
* stream handler recognizes the reported retirement notice for old model IDs.
|
|
27
|
-
* Pi exposes the remaining models as public IDs and surfaces the exact thinking
|
|
28
|
-
* levels advertised by the backend for each model.
|
|
28
|
+
* Removed 2026-11-18 per Google's models doc: `claude-opus-4-6-thinking`,
|
|
29
|
+
* `claude-sonnet-4-6`, `gpt-oss-120b-medium`. They are no longer selectable; the stream
|
|
30
|
+
* handler still recognizes their retirement notices, and pinned runtime overrides to the
|
|
31
|
+
* old wire IDs keep working until the backend drops them.
|
|
29
32
|
*/
|
|
30
33
|
export declare const ANTIGRAVITY_ROUTING: Record<string, AntigravityRouting>;
|
|
31
34
|
/**
|
package/dist/models/models.js
CHANGED
|
@@ -4,29 +4,54 @@ export const PROVIDER_NAME = "Antigravity";
|
|
|
4
4
|
/**
|
|
5
5
|
* Public selectable model IDs → backend request model IDs by thinking effort.
|
|
6
6
|
*
|
|
7
|
-
* Catalog mirrors `agy models` (Antigravity CLI), which
|
|
8
|
-
* - Gemini 4 Argon (Low / Medium / High) —
|
|
7
|
+
* Catalog mirrors `agy models` (Antigravity CLI) and the 2026-11 models doc, which advertises:
|
|
8
|
+
* - Gemini 4 Argon (Low / Medium / High) — CONFIRMED: launched 2026-10-13; wire IDs
|
|
9
|
+
* `gemini-4-argon-{low,medium,high}` verified against live `fetchAvailableModels`
|
|
10
|
+
* (opencodex 2026-10-14, codex2api 2026-10-16). Entitlement-gated (Ultra / Enterprise /
|
|
11
|
+
* paid Pro); requests fall back to Gemini 3.8 Flash when the backend rejects it.
|
|
12
|
+
* - Gemini 4 Carbon (Low / Medium / High) — launched 2026-11-10 (changelog v2.31.0);
|
|
13
|
+
* CCA wire IDs follow the family pattern but are UNVERIFIED against a live listing,
|
|
14
|
+
* so requests fall back through Argon to Gemini 3.8 Flash when rejected.
|
|
15
|
+
* - Gemini 4 Hydrogen (Low / Medium / High / xHigh) — launched 2026-11-12; the four
|
|
16
|
+
* SKUs incl. the new `-xhigh` tier were observed in live discovery (oh-my-pi 7c74c203,
|
|
17
|
+
* opencodex #8644 2026-11-13). Falls back through Carbon → Argon → 3.8 Flash.
|
|
9
18
|
* - Gemini 3.8 Flash (Low / Medium / High)
|
|
10
|
-
* - Gemini 3.7 Flash (Low / Medium / High)
|
|
11
|
-
*
|
|
19
|
+
* - Gemini 3.7 Flash (Low / Medium / High) — still served, single `gemini-3.7-flash-tiered`
|
|
20
|
+
* wire id on newer discovery payloads; Enterprise-only per the 2026-11 models doc.
|
|
21
|
+
* - Gemini 3.6 Flash (Low / Medium / High) — Enterprise-only; effectively absent from CCA
|
|
22
|
+
* for non-Enterprise accounts since 3.7 shipped, but kept selectable for entitled ones.
|
|
12
23
|
* - Gemini 3.1 Pro (Low / High)
|
|
13
|
-
* - Claude Sonnet 4.6 (Thinking)
|
|
14
|
-
* - Claude Opus 4.6 (Thinking)
|
|
15
24
|
* - Claude Opus 5.5 (Low / Medium / High)
|
|
16
25
|
* - Claude Sonnet 5.5 (Low / Medium / High)
|
|
17
|
-
* - GPT-OSS 120B (Medium)
|
|
18
26
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* Gemini 3.5 Flash is intentionally omitted from the selectable catalog; the
|
|
25
|
-
* stream handler recognizes the reported retirement notice for old model IDs.
|
|
26
|
-
* Pi exposes the remaining models as public IDs and surfaces the exact thinking
|
|
27
|
-
* levels advertised by the backend for each model.
|
|
27
|
+
* Removed 2026-11-18 per Google's models doc: `claude-opus-4-6-thinking`,
|
|
28
|
+
* `claude-sonnet-4-6`, `gpt-oss-120b-medium`. They are no longer selectable; the stream
|
|
29
|
+
* handler still recognizes their retirement notices, and pinned runtime overrides to the
|
|
30
|
+
* old wire IDs keep working until the backend drops them.
|
|
28
31
|
*/
|
|
29
32
|
export const ANTIGRAVITY_ROUTING = {
|
|
33
|
+
"gemini-4-hydrogen": {
|
|
34
|
+
off: "gemini-4-hydrogen-low",
|
|
35
|
+
routing: {
|
|
36
|
+
minimal: "gemini-4-hydrogen-low",
|
|
37
|
+
low: "gemini-4-hydrogen-low",
|
|
38
|
+
medium: "gemini-4-hydrogen-medium",
|
|
39
|
+
high: "gemini-4-hydrogen-high",
|
|
40
|
+
xhigh: "gemini-4-hydrogen-xhigh",
|
|
41
|
+
},
|
|
42
|
+
defaultRequestId: "gemini-4-hydrogen-low",
|
|
43
|
+
},
|
|
44
|
+
"gemini-4-carbon": {
|
|
45
|
+
off: "gemini-4-carbon-low",
|
|
46
|
+
routing: {
|
|
47
|
+
minimal: "gemini-4-carbon-low",
|
|
48
|
+
low: "gemini-4-carbon-low",
|
|
49
|
+
medium: "gemini-4-carbon-medium",
|
|
50
|
+
high: "gemini-4-carbon-high",
|
|
51
|
+
xhigh: "gemini-4-carbon-high",
|
|
52
|
+
},
|
|
53
|
+
defaultRequestId: "gemini-4-carbon-low",
|
|
54
|
+
},
|
|
30
55
|
"gemini-4-argon": {
|
|
31
56
|
off: "gemini-4-argon-low",
|
|
32
57
|
routing: {
|
|
@@ -130,6 +155,8 @@ export const ANTIGRAVITY_ROUTING = {
|
|
|
130
155
|
},
|
|
131
156
|
defaultRequestId: "gemini-3.6-flash-low",
|
|
132
157
|
},
|
|
158
|
+
// Removed-from-catalog IDs keep their routing so a pinned frontend override still
|
|
159
|
+
// resolves to the right wire id until the backend drops the model (2026-11-18).
|
|
133
160
|
"gpt-oss-120b": {
|
|
134
161
|
off: "gpt-oss-120b-medium",
|
|
135
162
|
routing: {
|
|
@@ -146,6 +173,16 @@ export const ANTIGRAVITY_ROUTING = {
|
|
|
146
173
|
* Requesting more than these limits returns a 400 Bad Request from the API.
|
|
147
174
|
*/
|
|
148
175
|
export const RUNTIME_MAX_OUTPUT_TOKENS = {
|
|
176
|
+
// Gemini 4 family: 3.8-tier value as provisional estimate; no verified 4-family limit.
|
|
177
|
+
"gemini-4-carbon": 65536,
|
|
178
|
+
"gemini-4-carbon-low": 65536,
|
|
179
|
+
"gemini-4-carbon-medium": 65536,
|
|
180
|
+
"gemini-4-carbon-high": 65536,
|
|
181
|
+
"gemini-4-hydrogen": 65536,
|
|
182
|
+
"gemini-4-hydrogen-low": 65536,
|
|
183
|
+
"gemini-4-hydrogen-medium": 65536,
|
|
184
|
+
"gemini-4-hydrogen-high": 65536,
|
|
185
|
+
"gemini-4-hydrogen-xhigh": 65536,
|
|
149
186
|
// Provisional: family fallback, not a verified Gemini 4 limit.
|
|
150
187
|
"gemini-4-argon": 65536,
|
|
151
188
|
"gemini-4-argon-low": 65536,
|
|
@@ -200,7 +237,6 @@ const geminiFlashCost = { input: 0.1, output: 0.4, cacheRead: 0.025, cacheWrite:
|
|
|
200
237
|
const geminiProCost = { input: 1.25, output: 5.0, cacheRead: 0.3125, cacheWrite: 1.25 };
|
|
201
238
|
const claudeSonnetCost = { input: 3.0, output: 15.0, cacheRead: 0.3, cacheWrite: 3.75 };
|
|
202
239
|
const claudeOpusCost = { input: 15.0, output: 75.0, cacheRead: 1.5, cacheWrite: 18.75 };
|
|
203
|
-
const gptOssCost = { input: 0.6, output: 2.4, cacheRead: 0.15, cacheWrite: 0.6 };
|
|
204
240
|
// A null entry is intentionally hidden by Pi. Do not collapse levels that happen to
|
|
205
241
|
// route to the same runtime ID: the UI must reflect the levels the backend advertises.
|
|
206
242
|
const thinkingLevelMaps = {
|
|
@@ -213,6 +249,15 @@ const thinkingLevelMaps = {
|
|
|
213
249
|
xhigh: null,
|
|
214
250
|
max: null,
|
|
215
251
|
},
|
|
252
|
+
lowMediumHighXhigh: {
|
|
253
|
+
off: null,
|
|
254
|
+
minimal: null,
|
|
255
|
+
low: "low",
|
|
256
|
+
medium: "medium",
|
|
257
|
+
high: "high",
|
|
258
|
+
xhigh: "xhigh",
|
|
259
|
+
max: null,
|
|
260
|
+
},
|
|
216
261
|
lowHigh: {
|
|
217
262
|
off: null,
|
|
218
263
|
minimal: null,
|
|
@@ -256,8 +301,10 @@ const claude55ThinkingLevelMaps = {
|
|
|
256
301
|
high: thinkingLevelMaps.thinking,
|
|
257
302
|
};
|
|
258
303
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
304
|
+
* Claude Opus 5.5 and Sonnet 5.5 are officially served by Antigravity (confirmed in the
|
|
305
|
+
* 2026-11 models doc and observed in live discovery since 2026-10-03). The per-tier cost,
|
|
306
|
+
* context window, and output caps below remain same-family estimates — Google does not
|
|
307
|
+
* publish 5.5-specific numbers — but the models themselves are first-class.
|
|
261
308
|
*/
|
|
262
309
|
function claude55Models(family) {
|
|
263
310
|
const familyName = family === "opus" ? "Opus" : "Sonnet";
|
|
@@ -280,7 +327,8 @@ function claude55Models(family) {
|
|
|
280
327
|
/** Selectable provider models; effort variants share public IDs where routing supports them. */
|
|
281
328
|
export const ANTIGRAVITY_MODELS = [
|
|
282
329
|
{
|
|
283
|
-
//
|
|
330
|
+
// Wire IDs verified against live discovery (2026-10-14); cost/context are
|
|
331
|
+
// Pro-tier estimates and the output cap is the 3.8-tier value.
|
|
284
332
|
id: "gemini-4-argon",
|
|
285
333
|
name: "Gemini 4 Argon (Antigravity)",
|
|
286
334
|
reasoning: true,
|
|
@@ -290,6 +338,30 @@ export const ANTIGRAVITY_MODELS = [
|
|
|
290
338
|
contextWindow: 1048576,
|
|
291
339
|
maxTokens: 65536,
|
|
292
340
|
},
|
|
341
|
+
{
|
|
342
|
+
// Launched 2026-11-10. Carbon-specific cost/context/output are unverified;
|
|
343
|
+
// values reuse the Gemini 4 family estimates.
|
|
344
|
+
id: "gemini-4-carbon",
|
|
345
|
+
name: "Gemini 4 Carbon (Antigravity)",
|
|
346
|
+
reasoning: true,
|
|
347
|
+
thinkingLevelMap: thinkingLevelMaps.lowMediumHigh,
|
|
348
|
+
input: ["text", "image"],
|
|
349
|
+
cost: geminiProCost,
|
|
350
|
+
contextWindow: 1048576,
|
|
351
|
+
maxTokens: 65536,
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
// Launched 2026-11-12 with the backend's first -xhigh tier. Hydrogen-specific
|
|
355
|
+
// cost/context/output are unverified; values reuse the Gemini 4 family estimates.
|
|
356
|
+
id: "gemini-4-hydrogen",
|
|
357
|
+
name: "Gemini 4 Hydrogen (Antigravity)",
|
|
358
|
+
reasoning: true,
|
|
359
|
+
thinkingLevelMap: thinkingLevelMaps.lowMediumHighXhigh,
|
|
360
|
+
input: ["text", "image"],
|
|
361
|
+
cost: geminiProCost,
|
|
362
|
+
contextWindow: 1048576,
|
|
363
|
+
maxTokens: 65536,
|
|
364
|
+
},
|
|
293
365
|
{
|
|
294
366
|
id: "gemini-3.8-flash",
|
|
295
367
|
name: "Gemini 3.8 Flash (Antigravity)",
|
|
@@ -320,28 +392,8 @@ export const ANTIGRAVITY_MODELS = [
|
|
|
320
392
|
contextWindow: 1048576,
|
|
321
393
|
maxTokens: 65536,
|
|
322
394
|
},
|
|
323
|
-
{
|
|
324
|
-
id: "claude-opus-4-6",
|
|
325
|
-
name: "Claude Opus 4.6 (Antigravity)",
|
|
326
|
-
reasoning: true,
|
|
327
|
-
thinkingLevelMap: thinkingLevelMaps.thinking,
|
|
328
|
-
input: ["text", "image"],
|
|
329
|
-
cost: claudeOpusCost,
|
|
330
|
-
contextWindow: 250000,
|
|
331
|
-
maxTokens: 64000,
|
|
332
|
-
},
|
|
333
395
|
...claude55Models("opus"),
|
|
334
396
|
...claude55Models("sonnet"),
|
|
335
|
-
{
|
|
336
|
-
id: "claude-sonnet-4-6",
|
|
337
|
-
name: "Claude Sonnet 4.6 (Antigravity)",
|
|
338
|
-
reasoning: true,
|
|
339
|
-
thinkingLevelMap: thinkingLevelMaps.thinking,
|
|
340
|
-
input: ["text", "image"],
|
|
341
|
-
cost: claudeSonnetCost,
|
|
342
|
-
contextWindow: 200000,
|
|
343
|
-
maxTokens: 64000,
|
|
344
|
-
},
|
|
345
397
|
{
|
|
346
398
|
id: "gemini-3.1-pro",
|
|
347
399
|
name: "Gemini 3.1 Pro (Antigravity)",
|
|
@@ -352,16 +404,6 @@ export const ANTIGRAVITY_MODELS = [
|
|
|
352
404
|
contextWindow: 1048576,
|
|
353
405
|
maxTokens: 65535,
|
|
354
406
|
},
|
|
355
|
-
{
|
|
356
|
-
id: "gpt-oss-120b",
|
|
357
|
-
name: "GPT-OSS 120B (Antigravity)",
|
|
358
|
-
reasoning: true,
|
|
359
|
-
thinkingLevelMap: thinkingLevelMaps.medium,
|
|
360
|
-
input: ["text"],
|
|
361
|
-
cost: gptOssCost,
|
|
362
|
-
contextWindow: 131072,
|
|
363
|
-
maxTokens: 32768,
|
|
364
|
-
},
|
|
365
407
|
];
|
|
366
408
|
/** Resolve public model id + thinking effort to Antigravity runtime model id. */
|
|
367
409
|
export function getAntigravityRequestModelId(modelId, effort) {
|
|
@@ -393,6 +435,22 @@ export function getAntigravityRequestModelId(modelId, effort) {
|
|
|
393
435
|
* provide a fallback runtime model ID (e.g. Gemini 3.6 Flash) to maintain availability.
|
|
394
436
|
*/
|
|
395
437
|
export function getFallbackRuntimeModel(runtimeModel, effort) {
|
|
438
|
+
// Only Hydrogen advertises an -xhigh wire id; Carbon and Argon top out at -high,
|
|
439
|
+
// so a Hydrogen xHigh fallback must downgrade the tier when it crosses families.
|
|
440
|
+
const carbonTarget = runtimeModel.startsWith("gemini-4-hydrogen-")
|
|
441
|
+
? runtimeModel.replace("gemini-4-hydrogen-", "gemini-4-carbon-").replace(/-xhigh$/, "-high")
|
|
442
|
+
: undefined;
|
|
443
|
+
if (runtimeModel === "gemini-4-hydrogen") {
|
|
444
|
+
return "gemini-4-carbon-low";
|
|
445
|
+
}
|
|
446
|
+
if (carbonTarget)
|
|
447
|
+
return carbonTarget;
|
|
448
|
+
if (runtimeModel === "gemini-4-carbon") {
|
|
449
|
+
return "gemini-4-argon-low";
|
|
450
|
+
}
|
|
451
|
+
if (runtimeModel.startsWith("gemini-4-carbon-")) {
|
|
452
|
+
return runtimeModel.replace("gemini-4-carbon-", "gemini-4-argon-").replace(/-xhigh$/, "-high");
|
|
453
|
+
}
|
|
396
454
|
if (runtimeModel === "gemini-4-argon") {
|
|
397
455
|
return "gemini-3.8-flash-low";
|
|
398
456
|
}
|
package/dist/stream/stream.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ import { type AntigravitySessionState } from "../utils/util.js";
|
|
|
5
5
|
export { ANTIGRAVITY_API };
|
|
6
6
|
/** Plan quota is deterministic; everything else on a 429 is a transient throttle. */
|
|
7
7
|
export declare function isPlanQuotaError(status: number | undefined, text: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Transient 429s may carry a server-provided Retry-After (seconds or HTTP-date, CPA
|
|
10
|
+
* issue #6646). Trust it over the local backoff when it is short enough to be worth a
|
|
11
|
+
* retry; a longer value is a cooldown that will not clear inside this loop.
|
|
12
|
+
*/
|
|
13
|
+
export declare const THROTTLE_RETRY_AFTER_CAP_SECONDS = 60;
|
|
14
|
+
export declare function parseRetryAfterSeconds(raw: string | null | undefined): number | undefined;
|
|
8
15
|
/** Exported for unit tests. */
|
|
9
16
|
export declare function convertMessages(model: Model<Api>, context: TranscriptContext, runtimeModel: string): GeminiContent[];
|
|
10
17
|
/**
|
package/dist/stream/stream.js
CHANGED
|
@@ -49,6 +49,28 @@ function sleep(ms, signal) {
|
|
|
49
49
|
export function isPlanQuotaError(status, text) {
|
|
50
50
|
return status === 429 && /Individual quota reached/i.test(text);
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Transient 429s may carry a server-provided Retry-After (seconds or HTTP-date, CPA
|
|
54
|
+
* issue #6646). Trust it over the local backoff when it is short enough to be worth a
|
|
55
|
+
* retry; a longer value is a cooldown that will not clear inside this loop.
|
|
56
|
+
*/
|
|
57
|
+
export const THROTTLE_RETRY_AFTER_CAP_SECONDS = 60;
|
|
58
|
+
export function parseRetryAfterSeconds(raw) {
|
|
59
|
+
if (!raw)
|
|
60
|
+
return undefined;
|
|
61
|
+
const trimmed = raw.trim();
|
|
62
|
+
if (!trimmed)
|
|
63
|
+
return undefined;
|
|
64
|
+
if (/^\d+$/.test(trimmed)) {
|
|
65
|
+
const seconds = Number(trimmed);
|
|
66
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds : undefined;
|
|
67
|
+
}
|
|
68
|
+
const date = Date.parse(trimmed);
|
|
69
|
+
if (Number.isNaN(date))
|
|
70
|
+
return undefined;
|
|
71
|
+
const seconds = Math.round((date - Date.now()) / 1000);
|
|
72
|
+
return seconds >= 0 ? seconds : 0;
|
|
73
|
+
}
|
|
52
74
|
/**
|
|
53
75
|
* pi chooses auto-retry by matching the error text (`isRetryableAssistantError`) and
|
|
54
76
|
* checks account-limit phrases like "quota exceeded" BEFORE retryable ones. Google's
|
|
@@ -495,16 +517,30 @@ export function mapStopReason(reason) {
|
|
|
495
517
|
return StopReason.Length;
|
|
496
518
|
return reason ? StopReason.Error : StopReason.Stop;
|
|
497
519
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
520
|
+
/**
|
|
521
|
+
* Backends answer retired models with a plain text notice instead of an error. The 3.5
|
|
522
|
+
* wording is the observed template; the 2026-11-18 removals (Claude 4.6, Sonnet 4.6,
|
|
523
|
+
* GPT-OSS 120B) are expected to reuse it. Match on the model name prefix, not the full
|
|
524
|
+
* sentence, so wording drift on the suffix stays harmless.
|
|
525
|
+
*/
|
|
526
|
+
const RETIRED_NOTICE_PREFIXES = [
|
|
527
|
+
"gemini 3.5 flash is no longer available. please switch to",
|
|
528
|
+
"claude-opus-4-6 is no longer available",
|
|
529
|
+
"claude-sonnet-4-6 is no longer available",
|
|
530
|
+
"gpt-oss-120b is no longer available",
|
|
531
|
+
];
|
|
532
|
+
const RETIRED_RUNTIME_PATTERN = /^(?:gemini-3\.5-flash(?:-|$)|gemini-3-flash-agent$|claude-opus-4-6|claude-sonnet-4-6|gpt-oss-120b)/i;
|
|
533
|
+
function isRetiredRuntime(runtimeModel) {
|
|
534
|
+
return RETIRED_RUNTIME_PATTERN.test(runtimeModel);
|
|
501
535
|
}
|
|
502
536
|
function retiredNoticePrefixState(text) {
|
|
503
537
|
const normalized = text.trimStart().replace(/\s+/g, " ").toLowerCase();
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
538
|
+
for (const prefix of RETIRED_NOTICE_PREFIXES) {
|
|
539
|
+
if (normalized.startsWith(prefix))
|
|
540
|
+
return "match";
|
|
541
|
+
if (prefix.startsWith(normalized) && normalized.length > 0)
|
|
542
|
+
return "possible";
|
|
543
|
+
}
|
|
508
544
|
return "no-match";
|
|
509
545
|
}
|
|
510
546
|
/**
|
|
@@ -600,6 +636,16 @@ export function friendlyAntigravityError(status, text) {
|
|
|
600
636
|
if (/verify your account|VALIDATION_REQUIRED/i.test(msg)) {
|
|
601
637
|
return formatAccountValidation({ message: msg });
|
|
602
638
|
}
|
|
639
|
+
// Google is actively enforcing third-party OAuth use (403 PERMISSION_DENIED,
|
|
640
|
+
// reason TOS_VIOLATION; the appeal copy names "third party software"). The reason
|
|
641
|
+
// lives in error.details, which jsonOrTextError drops — match the raw body. Retries,
|
|
642
|
+
// re-login and model switches do not clear it, and the account itself is at risk.
|
|
643
|
+
if (/TOS_VIOLATION|third[- ]party (software|tools|services|clients?)/i.test(text)) {
|
|
644
|
+
return ("Antigravity flagged this account for third-party access (TOS_VIOLATION). " +
|
|
645
|
+
"Retries and re-login will not clear it; further use may get the account suspended. " +
|
|
646
|
+
"Next: stop using third-party clients on this account and appeal through Google support. " +
|
|
647
|
+
`Backend said: ${msg}`);
|
|
648
|
+
}
|
|
603
649
|
if (/permission|forbidden|access/i.test(msg)) {
|
|
604
650
|
return "Antigravity access was denied for this account or project. Next: try another model, re-login, or use an account with access.";
|
|
605
651
|
}
|
|
@@ -816,8 +862,8 @@ export async function streamResponse(response, stream, output, model, sessionSta
|
|
|
816
862
|
// The response is being discarded; cancellation is best-effort.
|
|
817
863
|
}
|
|
818
864
|
reader.releaseLock();
|
|
819
|
-
throw new Error("Antigravity reports that
|
|
820
|
-
"Next: switch to
|
|
865
|
+
throw new Error("Antigravity reports that this model has been retired and is no longer available. " +
|
|
866
|
+
"Next: switch to a current catalog model (see /antigravity.models).");
|
|
821
867
|
}
|
|
822
868
|
if (noticeState !== "possible")
|
|
823
869
|
flushPendingRetiredNoticeParts();
|
|
@@ -981,8 +1027,18 @@ export function streamAntigravity(model, context, options) {
|
|
|
981
1027
|
break;
|
|
982
1028
|
// Every other 429 is a transient throttle. Back off on the same endpoint
|
|
983
1029
|
// instead of hopping regions, which multiplies load on a throttled account.
|
|
984
|
-
|
|
985
|
-
|
|
1030
|
+
// Honor a server Retry-After when it is short; a longer one is a cooldown
|
|
1031
|
+
// that will not clear inside this loop, so burn no attempts on it.
|
|
1032
|
+
const retryAfterSeconds = parseRetryAfterSeconds(response.headers.get("retry-after"));
|
|
1033
|
+
const retryable = response.status === 429 &&
|
|
1034
|
+
throttleAttempt < THROTTLE_MAX_RETRIES &&
|
|
1035
|
+
(retryAfterSeconds === undefined ||
|
|
1036
|
+
retryAfterSeconds <= THROTTLE_RETRY_AFTER_CAP_SECONDS);
|
|
1037
|
+
if (retryable) {
|
|
1038
|
+
const delayMs = retryAfterSeconds !== undefined
|
|
1039
|
+
? retryAfterSeconds * 1000
|
|
1040
|
+
: throttleBaseDelayMs() * 2 ** throttleAttempt;
|
|
1041
|
+
await sleep(delayMs, opts.signal);
|
|
986
1042
|
throttleAttempt += 1;
|
|
987
1043
|
continue;
|
|
988
1044
|
}
|
|
@@ -1057,7 +1113,7 @@ export function streamAntigravity(model, context, options) {
|
|
|
1057
1113
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
1058
1114
|
};
|
|
1059
1115
|
output.stopReason = "stop";
|
|
1060
|
-
received = await streamResponse(response, stream, output, model, sessionState,
|
|
1116
|
+
received = await streamResponse(response, stream, output, model, sessionState, isRetiredRuntime(runtimeModel));
|
|
1061
1117
|
if (received)
|
|
1062
1118
|
break;
|
|
1063
1119
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { GlobalUsageBridge, UsageAccount, UsageProviderAdapter } from "pi-usage-core";
|
|
3
|
+
import type { AccountUsage } from "../types/types.js";
|
|
4
|
+
declare global {
|
|
5
|
+
var __PI_USAGE__: GlobalUsageBridge | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function convertUsageToAccount(usage: AccountUsage): UsageAccount;
|
|
8
|
+
export declare function createAntigravityUsageAdapter(): UsageProviderAdapter;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the `pi-usage-core` extension is loaded in this process.
|
|
11
|
+
*
|
|
12
|
+
* The core installs `globalThis.__PI_USAGE__` while its extension factory runs, so a lazy
|
|
13
|
+
* check is required: extension load order between the two packages is not guaranteed, and
|
|
14
|
+
* this package must stay usable without the core (`pi-usage-core` is a devDependency that
|
|
15
|
+
* supplies types only, never a runtime import).
|
|
16
|
+
*/
|
|
17
|
+
export declare function isUsageCoreAvailable(): boolean;
|
|
18
|
+
export declare function registerAntigravityUsageAdapter(pi: ExtensionAPI): UsageProviderAdapter;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { PROVIDER_ID } from "../models/models.js";
|
|
2
|
+
import { runWithDetachedDiagnostics } from "../diagnostics/diagnostics.js";
|
|
3
|
+
import { maskEmail } from "../utils/security.js";
|
|
4
|
+
import { fetchAccountUsage, resolveApiKeyFromContext } from "./usage.js";
|
|
5
|
+
/**
|
|
6
|
+
* Map a quota bucket's window onto a footer period. `window` is authoritative when present;
|
|
7
|
+
* the label is consulted only when `window` is missing or unrecognized, because a label can
|
|
8
|
+
* describe a rolling detail ("Weekly (rolling 5h)") that must not override the real window.
|
|
9
|
+
* Unrecognized input stays undefined so the footer falls back to the bucket label.
|
|
10
|
+
*/
|
|
11
|
+
const PERIOD_PATTERNS = [
|
|
12
|
+
// "FIVE_HOURS", "SESSION_5H", "WINDOW_5H", "ROLLING_5_HOURS", "5-hour session".
|
|
13
|
+
// The lookbehind rejects decimals so "2.5h" is not read as a 5-hour window.
|
|
14
|
+
[/\bfive\b|(?<![\d.])5\s*(?:hours?|hrs?|h)\b/, "5h"],
|
|
15
|
+
[/\b(?:daily|per\s+day)\b/, "daily"],
|
|
16
|
+
[/\b(?:weekly|per\s+week)\b/, "weekly"],
|
|
17
|
+
[/\b(?:monthly|per\s+month)\b/, "monthly"],
|
|
18
|
+
];
|
|
19
|
+
function matchPeriod(raw) {
|
|
20
|
+
if (!raw)
|
|
21
|
+
return undefined;
|
|
22
|
+
// `_` counts as a word character, so "ROLLING_5_HOURS" would defeat `\b`; split it out.
|
|
23
|
+
const normalized = raw.toLowerCase().replace(/[_-]+/g, " ");
|
|
24
|
+
for (const [pattern, period] of PERIOD_PATTERNS) {
|
|
25
|
+
if (pattern.test(normalized))
|
|
26
|
+
return period;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function toQuotaPeriod(bucket) {
|
|
31
|
+
return matchPeriod(bucket.window) ?? matchPeriod(bucket.displayName);
|
|
32
|
+
}
|
|
33
|
+
function uniquePoolId(base, taken) {
|
|
34
|
+
if (!taken.has(base)) {
|
|
35
|
+
taken.add(base);
|
|
36
|
+
return base;
|
|
37
|
+
}
|
|
38
|
+
let n = 2;
|
|
39
|
+
while (taken.has(`${base}-${n}`))
|
|
40
|
+
n++;
|
|
41
|
+
const id = `${base}-${n}`;
|
|
42
|
+
taken.add(id);
|
|
43
|
+
return id;
|
|
44
|
+
}
|
|
45
|
+
export function convertUsageToAccount(usage) {
|
|
46
|
+
const pools = [];
|
|
47
|
+
const takenPoolIds = new Set();
|
|
48
|
+
for (const group of usage.groups) {
|
|
49
|
+
const isGemini = /gemini/i.test(group.displayName);
|
|
50
|
+
const isClaude = /claude|gpt/i.test(group.displayName);
|
|
51
|
+
let poolId = group.displayName
|
|
52
|
+
.toLowerCase()
|
|
53
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
54
|
+
.replace(/(^-|-$)/g, "");
|
|
55
|
+
let modelKeys = [group.displayName.toLowerCase()];
|
|
56
|
+
if (isGemini) {
|
|
57
|
+
poolId = "gemini";
|
|
58
|
+
modelKeys = ["gemini"];
|
|
59
|
+
}
|
|
60
|
+
else if (isClaude) {
|
|
61
|
+
poolId = "claude-gpt";
|
|
62
|
+
modelKeys = ["claude", "gpt"];
|
|
63
|
+
}
|
|
64
|
+
const buckets = group.buckets.map((b) => {
|
|
65
|
+
const remFraction = typeof b.remainingFraction === "number" ? b.remainingFraction : 1.0;
|
|
66
|
+
const remaining = Math.round(remFraction * 100);
|
|
67
|
+
const used = Math.max(0, 100 - remaining);
|
|
68
|
+
const period = toQuotaPeriod(b);
|
|
69
|
+
let resetsAt;
|
|
70
|
+
if (b.resetTime) {
|
|
71
|
+
const ts = Date.parse(b.resetTime);
|
|
72
|
+
if (Number.isFinite(ts))
|
|
73
|
+
resetsAt = ts;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
id: b.bucketId || b.displayName,
|
|
77
|
+
label: b.displayName,
|
|
78
|
+
period,
|
|
79
|
+
used,
|
|
80
|
+
remaining,
|
|
81
|
+
unit: "percent",
|
|
82
|
+
resetsAt,
|
|
83
|
+
isPrimary: period === "5h",
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
// parseQuotaSummary keeps a named group even when every bucket was filtered out. Such a
|
|
87
|
+
// group carries no usage data, so drop it before it consumes a pool id.
|
|
88
|
+
if (buckets.length === 0)
|
|
89
|
+
continue;
|
|
90
|
+
const firstBucket = buckets[0];
|
|
91
|
+
if (firstBucket && !buckets.some((b) => b.isPrimary)) {
|
|
92
|
+
firstBucket.isPrimary = true;
|
|
93
|
+
}
|
|
94
|
+
pools.push({
|
|
95
|
+
id: uniquePoolId(poolId, takenPoolIds),
|
|
96
|
+
name: group.displayName,
|
|
97
|
+
description: group.description,
|
|
98
|
+
modelKeys,
|
|
99
|
+
buckets,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Fallback: the quota summary is subscription-gated, so free-tier accounts get no groups at
|
|
103
|
+
// all. Derive pools from the per-model catalog instead when nothing usable came back.
|
|
104
|
+
if (pools.length === 0 && usage.models.length > 0) {
|
|
105
|
+
const geminiModels = usage.models.filter((m) => m.modelId.startsWith("gemini") && m.remainingFraction !== undefined);
|
|
106
|
+
const claudeGptModels = usage.models.filter((m) => (m.modelId.startsWith("claude") || m.modelId.startsWith("gpt")) &&
|
|
107
|
+
m.remainingFraction !== undefined);
|
|
108
|
+
const refGemini = geminiModels[0];
|
|
109
|
+
if (refGemini) {
|
|
110
|
+
const remFraction = refGemini.remainingFraction ?? 1.0;
|
|
111
|
+
const remaining = Math.round(remFraction * 100);
|
|
112
|
+
const used = Math.max(0, 100 - remaining);
|
|
113
|
+
let resetsAt;
|
|
114
|
+
if (refGemini.resetTime) {
|
|
115
|
+
const ts = Date.parse(refGemini.resetTime);
|
|
116
|
+
if (Number.isFinite(ts))
|
|
117
|
+
resetsAt = ts;
|
|
118
|
+
}
|
|
119
|
+
pools.push({
|
|
120
|
+
id: "gemini",
|
|
121
|
+
name: "Gemini Models",
|
|
122
|
+
modelKeys: ["gemini"],
|
|
123
|
+
buckets: [
|
|
124
|
+
{
|
|
125
|
+
id: "gemini-shared",
|
|
126
|
+
label: "Gemini Pool",
|
|
127
|
+
// Per-model quotaInfo carries a remaining fraction and the next reset, not a
|
|
128
|
+
// window, so do not claim a 5h session the backend never reported.
|
|
129
|
+
period: "total",
|
|
130
|
+
used,
|
|
131
|
+
remaining,
|
|
132
|
+
unit: "percent",
|
|
133
|
+
resetsAt,
|
|
134
|
+
isPrimary: true,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const refClaudeGpt = claudeGptModels[0];
|
|
140
|
+
if (refClaudeGpt) {
|
|
141
|
+
const remFraction = refClaudeGpt.remainingFraction ?? 1.0;
|
|
142
|
+
const remaining = Math.round(remFraction * 100);
|
|
143
|
+
const used = Math.max(0, 100 - remaining);
|
|
144
|
+
let resetsAt;
|
|
145
|
+
if (refClaudeGpt.resetTime) {
|
|
146
|
+
const ts = Date.parse(refClaudeGpt.resetTime);
|
|
147
|
+
if (Number.isFinite(ts))
|
|
148
|
+
resetsAt = ts;
|
|
149
|
+
}
|
|
150
|
+
pools.push({
|
|
151
|
+
id: "claude-gpt",
|
|
152
|
+
name: "Claude & GPT Models",
|
|
153
|
+
modelKeys: ["claude", "gpt"],
|
|
154
|
+
buckets: [
|
|
155
|
+
{
|
|
156
|
+
id: "claude-gpt-shared",
|
|
157
|
+
label: "Claude & GPT Pool",
|
|
158
|
+
period: "total",
|
|
159
|
+
used,
|
|
160
|
+
remaining,
|
|
161
|
+
unit: "percent",
|
|
162
|
+
resetsAt,
|
|
163
|
+
isPrimary: true,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const metrics = [];
|
|
170
|
+
const planLabel = usage.planLabel || usage.paidTier?.name || usage.productTier?.name;
|
|
171
|
+
if (planLabel) {
|
|
172
|
+
metrics.push({
|
|
173
|
+
id: "plan-tier",
|
|
174
|
+
label: "Plan",
|
|
175
|
+
value: planLabel,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (usage.defaultAgentModelId) {
|
|
179
|
+
metrics.push({
|
|
180
|
+
id: "default-model",
|
|
181
|
+
label: "Default Model",
|
|
182
|
+
value: usage.defaultAgentModelId,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Report a quota failure rather than a "ready" account that renders nothing.
|
|
186
|
+
const hasBuckets = pools.some((p) => p.buckets.length > 0);
|
|
187
|
+
const isError = !hasBuckets && Boolean(usage.quotaSummaryError);
|
|
188
|
+
const status = isError ? "error" : "ready";
|
|
189
|
+
const errorMessage = isError ? usage.quotaSummaryError : undefined;
|
|
190
|
+
return {
|
|
191
|
+
id: usage.projectId || "antigravity-active",
|
|
192
|
+
name: "Account",
|
|
193
|
+
// Masked: the dashboard renders this verbatim, and this repo already masks account
|
|
194
|
+
// emails on other surfaces (maskEmail in utils/security.ts).
|
|
195
|
+
email: maskEmail(usage.email),
|
|
196
|
+
status,
|
|
197
|
+
errorMessage,
|
|
198
|
+
isActive: true,
|
|
199
|
+
lastUpdated: usage.fetchedAt || Date.now(),
|
|
200
|
+
pools,
|
|
201
|
+
metrics,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export function createAntigravityUsageAdapter() {
|
|
205
|
+
async function getAccounts(ctx) {
|
|
206
|
+
const apiKey = await resolveApiKeyFromContext(ctx);
|
|
207
|
+
if (!apiKey) {
|
|
208
|
+
return [
|
|
209
|
+
{
|
|
210
|
+
id: "antigravity-default",
|
|
211
|
+
name: "Google Antigravity",
|
|
212
|
+
status: "auth-required",
|
|
213
|
+
errorMessage: "No usable Antigravity credentials. Run /login antigravity to sign in again.",
|
|
214
|
+
pools: [],
|
|
215
|
+
lastUpdated: Date.now(),
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
// Detached bag: this runs on the footer/dashboard poll, so its failures must not
|
|
221
|
+
// become the `lastError` that /antigravity.doctor reports for the last model request.
|
|
222
|
+
const usage = await runWithDetachedDiagnostics(() => fetchAccountUsage(apiKey));
|
|
223
|
+
return [convertUsageToAccount(usage)];
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
return [
|
|
227
|
+
{
|
|
228
|
+
id: "antigravity-error",
|
|
229
|
+
name: "Google Antigravity",
|
|
230
|
+
status: "error",
|
|
231
|
+
errorMessage: err instanceof Error ? err.message : String(err),
|
|
232
|
+
pools: [],
|
|
233
|
+
lastUpdated: Date.now(),
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
id: PROVIDER_ID,
|
|
240
|
+
displayName: "Google Antigravity",
|
|
241
|
+
getAccounts,
|
|
242
|
+
// Closure rather than `this.getAccounts`: the registry calls adapters as methods today,
|
|
243
|
+
// but a detached reference must not break the refresh path.
|
|
244
|
+
refresh: (ctx) => getAccounts(ctx),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Whether the `pi-usage-core` extension is loaded in this process.
|
|
249
|
+
*
|
|
250
|
+
* The core installs `globalThis.__PI_USAGE__` while its extension factory runs, so a lazy
|
|
251
|
+
* check is required: extension load order between the two packages is not guaranteed, and
|
|
252
|
+
* this package must stay usable without the core (`pi-usage-core` is a devDependency that
|
|
253
|
+
* supplies types only, never a runtime import).
|
|
254
|
+
*/
|
|
255
|
+
export function isUsageCoreAvailable() {
|
|
256
|
+
return typeof globalThis.__PI_USAGE__?.register === "function";
|
|
257
|
+
}
|
|
258
|
+
export function registerAntigravityUsageAdapter(pi) {
|
|
259
|
+
const adapter = createAntigravityUsageAdapter();
|
|
260
|
+
pi.events.emit("pi-usage:register", adapter);
|
|
261
|
+
pi.events.on("pi-usage:discover", () => {
|
|
262
|
+
pi.events.emit("pi-usage:register", adapter);
|
|
263
|
+
});
|
|
264
|
+
if (globalThis.__PI_USAGE__?.register) {
|
|
265
|
+
globalThis.__PI_USAGE__.register(adapter);
|
|
266
|
+
}
|
|
267
|
+
pi.on("session_start", () => {
|
|
268
|
+
pi.events.emit("pi-usage:register", adapter);
|
|
269
|
+
});
|
|
270
|
+
return adapter;
|
|
271
|
+
}
|
package/dist/usage/index.d.ts
CHANGED
package/dist/usage/index.js
CHANGED
package/dist/usage/usage.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { AccountUsage } from "../types/types.js";
|
|
3
3
|
export declare function fetchAccountUsage(apiKeyRaw?: string): Promise<AccountUsage>;
|
|
4
4
|
export declare function formatUsageSummary(usage: AccountUsage): string;
|
|
5
5
|
export declare function formatModelsList(usage: AccountUsage, opts?: {
|
|
6
6
|
all?: boolean;
|
|
7
7
|
}): string;
|
|
8
|
-
export declare function resolveApiKeyFromContext(ctx: ExtensionCommandContext): Promise<string | undefined>;
|
|
8
|
+
export declare function resolveApiKeyFromContext(ctx: ExtensionContext | ExtensionCommandContext): Promise<string | undefined>;
|
package/dist/usage/usage.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { readStoredCredential } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import { antigravityHeaders, endpointCandidates, extractProjectId, parseApiKey, resolveProjectId, } from "../client/client.js";
|
|
3
|
+
import { PROVIDER_ID } from "../models/models.js";
|
|
2
4
|
import { setLastEndpoint, setLastError, setLastProjectId, setLastStatus, } from "../diagnostics/diagnostics.js";
|
|
3
5
|
import { isRecord } from "../utils/util.js";
|
|
4
6
|
import { safeError } from "../utils/security.js";
|
|
@@ -306,6 +308,7 @@ export async function fetchAccountUsage(apiKeyRaw) {
|
|
|
306
308
|
return {
|
|
307
309
|
projectId,
|
|
308
310
|
endpoint: summary?.endpoint ?? available.endpoint ?? assistResult?.endpoint,
|
|
311
|
+
email: creds.email,
|
|
309
312
|
productTier,
|
|
310
313
|
paidTier,
|
|
311
314
|
planLabel,
|
|
@@ -380,9 +383,30 @@ export function formatModelsList(usage, opts) {
|
|
|
380
383
|
}
|
|
381
384
|
export async function resolveApiKeyFromContext(ctx) {
|
|
382
385
|
try {
|
|
383
|
-
|
|
386
|
+
const key = await ctx.modelRegistry.getApiKeyForProvider("antigravity");
|
|
387
|
+
if (key)
|
|
388
|
+
return key;
|
|
384
389
|
}
|
|
385
390
|
catch {
|
|
386
|
-
|
|
391
|
+
// continue to fallback
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
// `readStoredCredential` owns the auth.json path and parsing, so this fallback cannot
|
|
395
|
+
// drift from the host's credential format.
|
|
396
|
+
const stored = readStoredCredential(PROVIDER_ID);
|
|
397
|
+
const access = typeof stored?.access === "string" ? stored.access : undefined;
|
|
398
|
+
const projectId = typeof stored?.projectId === "string" ? stored.projectId : undefined;
|
|
399
|
+
if (access && projectId) {
|
|
400
|
+
// A stored token without an expiry is still usable; only reject a known-expired one.
|
|
401
|
+
const expires = typeof stored?.expires === "number" ? stored.expires : undefined;
|
|
402
|
+
if (expires !== undefined && expires <= Date.now())
|
|
403
|
+
return undefined;
|
|
404
|
+
const email = typeof stored?.email === "string" ? stored.email : undefined;
|
|
405
|
+
return JSON.stringify({ token: access, projectId, ...(email ? { email } : {}) });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
// Ignore fallback errors
|
|
387
410
|
}
|
|
411
|
+
return undefined;
|
|
388
412
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyhuynhgiabuu/pi-oauth-antigravity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Google Antigravity OAuth provider extension for Pi with Gemini 3.8, prompt cache session affinity, and trajectory chaining.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@earendil-works/pi-ai": "1.2.0",
|
|
63
63
|
"@earendil-works/pi-coding-agent": "1.2.0",
|
|
64
64
|
"@types/node": "^22.20.1",
|
|
65
|
+
"pi-usage-core": "^0.1.0",
|
|
65
66
|
"tsx": "^4.20.6",
|
|
66
67
|
"typescript": "^7.0.2"
|
|
67
68
|
},
|