@herbertgao/pi-extensions 2026.11.18 → 2026.11.20
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 +5 -5
- package/THIRD_PARTY_NOTICES.md +3 -24
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/ask.js +6 -3
- package/node_modules/pi-typesafe/dist/auth.d.ts +31 -7
- package/node_modules/pi-typesafe/dist/auth.js +159 -55
- package/node_modules/pi-typesafe/dist/batch.d.ts +16 -2
- package/node_modules/pi-typesafe/dist/batch.js +62 -22
- package/node_modules/pi-typesafe/dist/calibrate.d.ts +38 -11
- package/node_modules/pi-typesafe/dist/calibrate.js +56 -24
- package/node_modules/pi-typesafe/dist/client.d.ts +13 -0
- package/node_modules/pi-typesafe/dist/client.js +67 -27
- package/node_modules/pi-typesafe/dist/errors.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/errors.js +105 -2
- package/node_modules/pi-typesafe/dist/extension.d.ts +106 -0
- package/node_modules/pi-typesafe/dist/extension.js +206 -106
- package/node_modules/pi-typesafe/dist/index.d.ts +8 -8
- package/node_modules/pi-typesafe/dist/index.js +3 -3
- package/node_modules/pi-typesafe/dist/key-prompt.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/key-prompt.js +23 -3
- package/node_modules/pi-typesafe/dist/login.d.ts +58 -1
- package/node_modules/pi-typesafe/dist/login.js +167 -13
- package/node_modules/pi-typesafe/dist/schema.d.ts +3 -0
- package/node_modules/pi-typesafe/dist/schema.js +47 -13
- package/node_modules/pi-typesafe/dist/ui.d.ts +2 -1
- package/node_modules/pi-typesafe/dist/usage.d.ts +53 -0
- package/node_modules/pi-typesafe/dist/usage.js +79 -40
- package/node_modules/pi-typesafe/package.json +3 -3
- package/package.json +12 -15
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { chmodSync, existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import type { OAuthCredentials } from "@earendil-works/pi-ai";
|
|
6
|
-
import { defaultProjectId } from "../client/client.js";
|
|
7
|
-
import type { AntigravityApiKey, AntigravityOAuthCredentials } from "../types/types.js";
|
|
8
|
-
import { refreshAntigravityToken } from "./oauth.js";
|
|
9
|
-
|
|
10
|
-
const ACCOUNTS_FILE = "antigravity-accounts.json";
|
|
11
|
-
const AUTH_FILE = "auth.json";
|
|
12
|
-
const REFRESH_SKEW_MS = 5 * 60 * 1000;
|
|
13
|
-
|
|
14
|
-
export type StoredAccount = AntigravityOAuthCredentials & {
|
|
15
|
-
accountId: string;
|
|
16
|
-
addedAt: number;
|
|
17
|
-
lastUsedAt: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type AccountsFile = {
|
|
21
|
-
version: 1;
|
|
22
|
-
activeAccountId?: string;
|
|
23
|
-
accounts: Record<string, StoredAccount>;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type AccountSummary = {
|
|
27
|
-
accountId: string;
|
|
28
|
-
email?: string;
|
|
29
|
-
active: boolean;
|
|
30
|
-
lastUsedAt: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function agentDir(): string {
|
|
34
|
-
return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function accountsPath(): string {
|
|
38
|
-
return join(agentDir(), ACCOUNTS_FILE);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function authPath(): string {
|
|
42
|
-
return join(agentDir(), AUTH_FILE);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function readJsonObject(path: string): Record<string, unknown> | undefined {
|
|
46
|
-
if (!existsSync(path)) return undefined;
|
|
47
|
-
try {
|
|
48
|
-
const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
|
|
49
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
|
|
50
|
-
return parsed as Record<string, unknown>;
|
|
51
|
-
} catch {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function writePrivateJson(path: string, value: unknown): void {
|
|
57
|
-
const tempPath = `${path}.${process.pid}.tmp`;
|
|
58
|
-
writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
59
|
-
chmodSync(tempPath, 0o600);
|
|
60
|
-
renameSync(tempPath, path);
|
|
61
|
-
chmodSync(path, 0o600);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function emptyStore(): AccountsFile {
|
|
65
|
-
return { version: 1, accounts: {} };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function isStoredAccount(value: unknown): value is StoredAccount {
|
|
69
|
-
if (!value || typeof value !== "object") return false;
|
|
70
|
-
const account = value as Partial<StoredAccount>;
|
|
71
|
-
return typeof account.refresh === "string" && account.refresh.length > 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function normalizeStore(value: Record<string, unknown> | undefined): AccountsFile {
|
|
75
|
-
if (!value || value.version !== 1 || !value.accounts || typeof value.accounts !== "object") {
|
|
76
|
-
return emptyStore();
|
|
77
|
-
}
|
|
78
|
-
const accounts: Record<string, StoredAccount> = {};
|
|
79
|
-
for (const [key, raw] of Object.entries(value.accounts as Record<string, unknown>)) {
|
|
80
|
-
if (!isStoredAccount(raw)) continue;
|
|
81
|
-
const accountId =
|
|
82
|
-
typeof raw.accountId === "string" && raw.accountId.trim() ? raw.accountId : key;
|
|
83
|
-
accounts[accountId] = { ...raw, accountId };
|
|
84
|
-
}
|
|
85
|
-
const activeAccountId =
|
|
86
|
-
typeof value.activeAccountId === "string"
|
|
87
|
-
? value.activeAccountId
|
|
88
|
-
: typeof value.activeEmail === "string"
|
|
89
|
-
? value.activeEmail
|
|
90
|
-
: undefined;
|
|
91
|
-
return {
|
|
92
|
-
version: 1,
|
|
93
|
-
activeAccountId: activeAccountId && accounts[activeAccountId] ? activeAccountId : undefined,
|
|
94
|
-
accounts,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function loadAccountStore(): AccountsFile {
|
|
99
|
-
return normalizeStore(readJsonObject(accountsPath()));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function saveAccountStore(store: AccountsFile): void {
|
|
103
|
-
writePrivateJson(accountsPath(), store);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function accountIdFor(credentials: OAuthCredentials): string {
|
|
107
|
-
const email = (credentials as AntigravityOAuthCredentials).email?.trim().toLowerCase();
|
|
108
|
-
if (email) return email;
|
|
109
|
-
return `account-${createHash("sha256").update(credentials.refresh).digest("hex").slice(0, 16)}`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function accountFromCredentials(
|
|
113
|
-
credentials: AntigravityOAuthCredentials,
|
|
114
|
-
existing?: StoredAccount,
|
|
115
|
-
): StoredAccount {
|
|
116
|
-
const now = Date.now();
|
|
117
|
-
return {
|
|
118
|
-
...credentials,
|
|
119
|
-
accountId: existing?.accountId || accountIdFor(credentials),
|
|
120
|
-
addedAt: existing?.addedAt || now,
|
|
121
|
-
lastUsedAt: now,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function sortedAccounts(store: AccountsFile): StoredAccount[] {
|
|
126
|
-
return Object.values(store.accounts).sort((a, b) => {
|
|
127
|
-
if (a.addedAt !== b.addedAt) return a.addedAt - b.addedAt;
|
|
128
|
-
return a.accountId.localeCompare(b.accountId);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function findAccount(
|
|
133
|
-
store: AccountsFile,
|
|
134
|
-
credentials: OAuthCredentials,
|
|
135
|
-
): StoredAccount | undefined {
|
|
136
|
-
const email = (credentials as AntigravityOAuthCredentials).email?.trim().toLowerCase();
|
|
137
|
-
return Object.values(store.accounts).find(
|
|
138
|
-
(account) =>
|
|
139
|
-
account.refresh === credentials.refresh ||
|
|
140
|
-
(email !== undefined && account.email?.trim().toLowerCase() === email),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function findAccountId(store: AccountsFile, selector: string): string | undefined {
|
|
145
|
-
const normalized = selector.trim().toLowerCase();
|
|
146
|
-
if (!normalized) return undefined;
|
|
147
|
-
const entries = sortedAccounts(store);
|
|
148
|
-
if (/^\d+$/.test(normalized)) {
|
|
149
|
-
const index = Number.parseInt(normalized, 10);
|
|
150
|
-
if (index >= 1 && index <= entries.length) return entries[index - 1]?.accountId;
|
|
151
|
-
return undefined;
|
|
152
|
-
}
|
|
153
|
-
return entries.find(
|
|
154
|
-
(account) =>
|
|
155
|
-
account.accountId.toLowerCase() === normalized ||
|
|
156
|
-
account.email?.trim().toLowerCase() === normalized,
|
|
157
|
-
)?.accountId;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function readAuthFile(): Record<string, unknown> {
|
|
161
|
-
const path = authPath();
|
|
162
|
-
if (!existsSync(path)) return {};
|
|
163
|
-
const parsed = readJsonObject(path);
|
|
164
|
-
if (!parsed) {
|
|
165
|
-
throw new Error("Refusing to overwrite unreadable Pi auth.json");
|
|
166
|
-
}
|
|
167
|
-
return parsed;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function writeActiveCredential(account: StoredAccount | undefined): void {
|
|
171
|
-
const auth = readAuthFile();
|
|
172
|
-
if (account) {
|
|
173
|
-
auth.antigravity = {
|
|
174
|
-
type: "oauth",
|
|
175
|
-
email: account.email,
|
|
176
|
-
access: account.access,
|
|
177
|
-
refresh: account.refresh,
|
|
178
|
-
expires: account.expires,
|
|
179
|
-
projectId: account.projectId,
|
|
180
|
-
};
|
|
181
|
-
} else {
|
|
182
|
-
delete auth.antigravity;
|
|
183
|
-
}
|
|
184
|
-
writePrivateJson(authPath(), auth);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function currentAuthCredentials(): AntigravityOAuthCredentials | undefined {
|
|
188
|
-
const current = readJsonObject(authPath())?.antigravity;
|
|
189
|
-
if (!current || typeof current !== "object") return undefined;
|
|
190
|
-
const record = current as Record<string, unknown>;
|
|
191
|
-
if (typeof record.refresh !== "string" || !record.refresh) return undefined;
|
|
192
|
-
return {
|
|
193
|
-
access: typeof record.access === "string" ? record.access : "",
|
|
194
|
-
refresh: record.refresh,
|
|
195
|
-
expires: typeof record.expires === "number" ? record.expires : 0,
|
|
196
|
-
projectId: typeof record.projectId === "string" ? record.projectId : undefined,
|
|
197
|
-
email: typeof record.email === "string" ? record.email : undefined,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function syncCurrentAuth(): void {
|
|
202
|
-
const credentials = currentAuthCredentials();
|
|
203
|
-
if (!credentials) return;
|
|
204
|
-
const store = loadAccountStore();
|
|
205
|
-
const existing = findAccount(store, credentials);
|
|
206
|
-
const account = accountFromCredentials(credentials, existing);
|
|
207
|
-
store.accounts[account.accountId] = account;
|
|
208
|
-
store.activeAccountId = account.accountId;
|
|
209
|
-
saveAccountStore(store);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export function rememberAccount(credentials: AntigravityOAuthCredentials): StoredAccount {
|
|
213
|
-
syncCurrentAuth();
|
|
214
|
-
const store = loadAccountStore();
|
|
215
|
-
const existing = findAccount(store, credentials);
|
|
216
|
-
const account = accountFromCredentials(credentials, existing);
|
|
217
|
-
store.accounts[account.accountId] = account;
|
|
218
|
-
store.activeAccountId = account.accountId;
|
|
219
|
-
saveAccountStore(store);
|
|
220
|
-
return account;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function updateRememberedAccount(
|
|
224
|
-
previous: OAuthCredentials,
|
|
225
|
-
credentials: AntigravityOAuthCredentials,
|
|
226
|
-
): void {
|
|
227
|
-
const store = loadAccountStore();
|
|
228
|
-
const existing = findAccount(store, previous);
|
|
229
|
-
if (!existing) return;
|
|
230
|
-
const account = accountFromCredentials(credentials, existing);
|
|
231
|
-
delete store.accounts[existing.accountId];
|
|
232
|
-
store.accounts[account.accountId] = account;
|
|
233
|
-
if (store.activeAccountId === existing.accountId) {
|
|
234
|
-
store.activeAccountId = account.accountId;
|
|
235
|
-
}
|
|
236
|
-
saveAccountStore(store);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function listAccounts(): AccountSummary[] {
|
|
240
|
-
syncCurrentAuth();
|
|
241
|
-
const store = loadAccountStore();
|
|
242
|
-
return sortedAccounts(store).map((account) => ({
|
|
243
|
-
accountId: account.accountId,
|
|
244
|
-
email: account.email,
|
|
245
|
-
active: account.accountId === store.activeAccountId,
|
|
246
|
-
lastUsedAt: account.lastUsedAt,
|
|
247
|
-
}));
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async function ensureFresh(account: StoredAccount): Promise<StoredAccount> {
|
|
251
|
-
if (account.access && account.expires > Date.now() + REFRESH_SKEW_MS) return account;
|
|
252
|
-
return accountFromCredentials(await refreshAntigravityToken(account), account);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function apiKeyFor(account: StoredAccount): AntigravityApiKey {
|
|
256
|
-
const email = account.email?.trim();
|
|
257
|
-
return {
|
|
258
|
-
token: account.access,
|
|
259
|
-
projectId: account.projectId || defaultProjectId(email || "antigravity-default"),
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export async function activateAccount(selector: string): Promise<StoredAccount> {
|
|
264
|
-
syncCurrentAuth();
|
|
265
|
-
const store = loadAccountStore();
|
|
266
|
-
const accountId = findAccountId(store, selector);
|
|
267
|
-
if (!accountId) throw new Error(`Antigravity account not found: ${selector}`);
|
|
268
|
-
const existing = store.accounts[accountId];
|
|
269
|
-
if (!existing) throw new Error(`Antigravity account not found: ${selector}`);
|
|
270
|
-
const account = await ensureFresh(existing);
|
|
271
|
-
account.lastUsedAt = Date.now();
|
|
272
|
-
store.accounts[account.accountId] = account;
|
|
273
|
-
store.activeAccountId = account.accountId;
|
|
274
|
-
saveAccountStore(store);
|
|
275
|
-
writeActiveCredential(account);
|
|
276
|
-
return account;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export async function removeAccount(selector: string): Promise<StoredAccount | undefined> {
|
|
280
|
-
syncCurrentAuth();
|
|
281
|
-
const store = loadAccountStore();
|
|
282
|
-
const accountId = findAccountId(store, selector);
|
|
283
|
-
if (!accountId) throw new Error(`Antigravity account not found: ${selector}`);
|
|
284
|
-
delete store.accounts[accountId];
|
|
285
|
-
let next: StoredAccount | undefined;
|
|
286
|
-
if (store.activeAccountId === accountId) {
|
|
287
|
-
next = sortedAccounts(store).sort((a, b) => b.lastUsedAt - a.lastUsedAt)[0];
|
|
288
|
-
if (next) {
|
|
289
|
-
next = await ensureFresh(next);
|
|
290
|
-
next.lastUsedAt = Date.now();
|
|
291
|
-
store.accounts[next.accountId] = next;
|
|
292
|
-
}
|
|
293
|
-
store.activeAccountId = next?.accountId;
|
|
294
|
-
writeActiveCredential(next);
|
|
295
|
-
}
|
|
296
|
-
saveAccountStore(store);
|
|
297
|
-
return next;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Switch to the next stored account that has not already been tried in this request.
|
|
302
|
-
* Used when Antigravity returns a hard quota wall (HTTP 429).
|
|
303
|
-
*/
|
|
304
|
-
export async function failoverToNextAccount(
|
|
305
|
-
triedAccessTokens: ReadonlySet<string>,
|
|
306
|
-
): Promise<AntigravityApiKey | undefined> {
|
|
307
|
-
syncCurrentAuth();
|
|
308
|
-
const store = loadAccountStore();
|
|
309
|
-
const candidates = sortedAccounts(store).filter(
|
|
310
|
-
(account) => !triedAccessTokens.has(account.access),
|
|
311
|
-
);
|
|
312
|
-
for (const candidate of candidates) {
|
|
313
|
-
try {
|
|
314
|
-
const account = await ensureFresh(candidate);
|
|
315
|
-
if (!account.access || triedAccessTokens.has(account.access)) continue;
|
|
316
|
-
account.lastUsedAt = Date.now();
|
|
317
|
-
store.accounts[account.accountId] = account;
|
|
318
|
-
store.activeAccountId = account.accountId;
|
|
319
|
-
saveAccountStore(store);
|
|
320
|
-
writeActiveCredential(account);
|
|
321
|
-
return apiKeyFor(account);
|
|
322
|
-
} catch {
|
|
323
|
-
// Skip accounts whose refresh token is no longer valid.
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return undefined;
|
|
327
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
loginAntigravity,
|
|
3
|
-
refreshAntigravityToken,
|
|
4
|
-
getApiKey,
|
|
5
|
-
CLIENT_ID,
|
|
6
|
-
CLIENT_SECRET,
|
|
7
|
-
REDIRECT_URI,
|
|
8
|
-
AUTH_URL,
|
|
9
|
-
TOKEN_URL,
|
|
10
|
-
SCOPES,
|
|
11
|
-
CALLBACK_HOST,
|
|
12
|
-
OAUTH_CALLBACK_TIMEOUT_MS,
|
|
13
|
-
} from "./oauth.js";
|
|
14
|
-
export type { OAuthCredentials, OAuthLoginCallbacks } from "./oauth.js";
|
|
15
|
-
export {
|
|
16
|
-
activateAccount,
|
|
17
|
-
failoverToNextAccount,
|
|
18
|
-
listAccounts,
|
|
19
|
-
rememberAccount,
|
|
20
|
-
removeAccount,
|
|
21
|
-
updateRememberedAccount,
|
|
22
|
-
} from "./accounts.js";
|
|
23
|
-
export type { AccountSummary, StoredAccount } from "./accounts.js";
|