@heyhuynhgiabuu/pi-oauth-antigravity 0.1.8 → 0.1.9
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 +18 -0
- package/README.md +8 -5
- package/dist/auth/oauth.js +1 -0
- package/dist/client/client.js +5 -1
- package/dist/diagnostics/diagnostics.d.ts +10 -0
- package/dist/diagnostics/diagnostics.js +12 -0
- package/dist/index.js +15 -4
- 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 +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.9] - 2026-10-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- 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.
|
|
14
|
+
- `/antigravity.doctor` now reports which usage mode is active on a `usageCore=` line.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- `/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.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- 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.
|
|
21
|
+
- 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.
|
|
22
|
+
- 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.
|
|
23
|
+
- Free-tier quota synthesized from the model catalog is labelled `total` instead of claiming a 5h session the backend never reported.
|
|
24
|
+
- Groups sharing a model family no longer produce duplicate pool ids.
|
|
25
|
+
- The account email is masked before it is displayed in a usage dashboard.
|
|
26
|
+
- 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.
|
|
27
|
+
|
|
10
28
|
## [0.1.8] - 2026-10-15
|
|
11
29
|
|
|
12
30
|
### Fixed
|
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ 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
|
|
@@ -71,18 +72,20 @@ pi -e /path/to/pi-oauth-antigravity/dist/index.js
|
|
|
71
72
|
|
|
72
73
|
## Slash Commands
|
|
73
74
|
|
|
74
|
-
- `/antigravity.usage` — View
|
|
75
|
-
- `/antigravity.models` — List dynamically fetched and statically registered models.
|
|
75
|
+
- `/antigravity.usage` — View shared quota pools (Gemini 5h/weekly, Claude+GPT 5h), plan tier, and reset countdowns.
|
|
76
|
+
- `/antigravity.models` — List dynamically fetched and statically registered models + remaining pool fraction.
|
|
76
77
|
- `/antigravity.doctor` — Diagnose OAuth state, refresh token health, and endpoint connectivity.
|
|
77
78
|
- `/antigravity.image <prompt> [--aspect 1:1|16:9|...]` — Generate images directly to your project.
|
|
78
79
|
|
|
80
|
+
> **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.
|
|
81
|
+
|
|
79
82
|
## Development
|
|
80
83
|
|
|
81
84
|
```bash
|
|
82
85
|
# Install dependencies
|
|
83
86
|
npm install
|
|
84
87
|
|
|
85
|
-
# Run unit tests (
|
|
88
|
+
# Run unit tests (84 tests)
|
|
86
89
|
npm test
|
|
87
90
|
|
|
88
91
|
# Typecheck
|
package/dist/auth/oauth.js
CHANGED
package/dist/client/client.js
CHANGED
|
@@ -93,7 +93,11 @@ export function parseApiKey(apiKeyRaw) {
|
|
|
93
93
|
const parsed = JSON.parse(apiKeyRaw);
|
|
94
94
|
if (!parsed.token || !parsed.projectId)
|
|
95
95
|
throw new Error("missing token or projectId");
|
|
96
|
-
return {
|
|
96
|
+
return {
|
|
97
|
+
token: parsed.token,
|
|
98
|
+
projectId: parsed.projectId,
|
|
99
|
+
...(parsed.email ? { email: parsed.email } : {}),
|
|
100
|
+
};
|
|
97
101
|
}
|
|
98
102
|
catch (error) {
|
|
99
103
|
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/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.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|
|
@@ -59,9 +59,10 @@
|
|
|
59
59
|
"undici": "^8.10.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@earendil-works/pi-ai": "1.
|
|
63
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
62
|
+
"@earendil-works/pi-ai": "1.3.0",
|
|
63
|
+
"@earendil-works/pi-coding-agent": "1.3.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
|
},
|