@timmyjl12/pi-agy-bridge 0.3.3 → 0.4.2
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/ARCHITECTURE.md +12 -0
- package/README.md +5 -2
- package/compat/baselines/agy-1.5.18.json +284 -0
- package/compat/matrix.json +1 -1
- package/compat/probe.ts +1 -1
- package/package.json +1 -1
- package/src/account-manager.ts +50 -2
- package/src/accounts.ts +81 -2
- package/src/acp/connection.ts +17 -1
- package/src/config.ts +12 -0
- package/src/conversation-store.ts +231 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +14 -2
- package/src/model-catalog.ts +48 -2
- package/src/provider.ts +10 -4
- package/src/runtime.ts +102 -8
- package/src/session-pool.ts +181 -7
- package/src/stream.ts +88 -6
- package/src/ui/menu.ts +96 -11
package/src/ui/menu.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { DEFAULT_ACCOUNT, labelFor, maskEmail, validateAccountName, type RequestLoginCode } from "../accounts.ts";
|
|
8
|
+
import { DEFAULT_ACCOUNT, labelFor, maskEmail, validateAccountName, validateApiKey, type RequestLoginCode } from "../accounts.ts";
|
|
9
9
|
import type { AccountManager, AccountView } from "../account-manager.ts";
|
|
10
10
|
import { buildDoctor, buildStatus } from "../doctor.ts";
|
|
11
11
|
import { CONFIG_ENV_NAMES } from "../config.ts";
|
|
@@ -20,6 +20,7 @@ const GROUPS = ["Accounts", "Add account", "Processes", "Diagnostics", "Settings
|
|
|
20
20
|
|
|
21
21
|
export function stateOf(view: AccountView): { text: string; tone: PanelItem["tone"] } {
|
|
22
22
|
if (!view.account.enabled) return { text: "disabled", tone: "muted" };
|
|
23
|
+
if (view.auth === "api-key" && !view.apiKey) return { text: "no API key", tone: "warn" };
|
|
23
24
|
if (view.identity && !view.identity.ok) return { text: "sign-in problem", tone: "error" };
|
|
24
25
|
if (!view.isDefault && !view.savedLogin) return { text: "not signed in", tone: "warn" };
|
|
25
26
|
if (view.running) return { text: `running · ${view.models?.length ?? "?"} models`, tone: "ok" };
|
|
@@ -34,11 +35,17 @@ export function emailOf(view: AccountView): string | undefined {
|
|
|
34
35
|
export function accountDetail(view: AccountView): string[] {
|
|
35
36
|
const lines: string[] = [];
|
|
36
37
|
const email = emailOf(view);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (view.auth === "api-key") {
|
|
39
|
+
lines.push(
|
|
40
|
+
`provider ${view.provider} · Gemini API key ${view.apiKey?.masked ?? "missing"} (set in this menu) · billed per token · Gemini models only`,
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
lines.push(
|
|
44
|
+
`provider ${view.provider} · ${view.isDefault ? "Windows/OS keyring login (agy's own)" : "own token file"}` +
|
|
45
|
+
` · account ${email ? maskEmail(email) : view.isDefault ? "(agy's signed-in user)" : "not recorded"}` +
|
|
46
|
+
(view.tier ? ` · ${view.tier}` : ""),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
42
49
|
lines.push(
|
|
43
50
|
`process ${view.running ? `running (pid ${view.pid ?? "?"})` : "stopped"} · sessions ${view.sessions.idle} reusable / ${view.sessions.busy} busy` +
|
|
44
51
|
(view.agyVersion ? ` · agy ${view.agyVersion}` : ""),
|
|
@@ -71,7 +78,7 @@ export async function mainView(manager: AccountManager, activeGroup?: string): P
|
|
|
71
78
|
label: `${view.isDefault ? "agy" : view.provider} ${view.isDefault ? "(default)" : view.account.alias ? `(${view.account.id})` : ""}`.trim(),
|
|
72
79
|
value: state.text,
|
|
73
80
|
tone: state.tone,
|
|
74
|
-
description: `${email ? maskEmail(email) : view.isDefault ? "agy's own login" : "no account recorded"} · Enter for actions: sign in, alias, enable/disable, check, reset, remove`,
|
|
81
|
+
description: `${view.auth === "api-key" ? `Gemini API key${view.apiKey ? ` ${view.apiKey.masked}` : " (missing)"}` : email ? maskEmail(email) : view.isDefault ? "agy's own login" : "no account recorded"} · Enter for actions: sign in, API key, alias, enable/disable, check, reset, remove`,
|
|
75
82
|
search: `${view.account.id} ${view.account.alias ?? ""} ${email ?? ""} ${view.provider}`,
|
|
76
83
|
});
|
|
77
84
|
}
|
|
@@ -124,7 +131,10 @@ export async function mainView(manager: AccountManager, activeGroup?: string): P
|
|
|
124
131
|
help("commands", "Commands", "/agy-bridge accounts | add <id> [alias] | login <id> | alias <id> <alias> | enable|disable <id> | remove <id> | check [id] | reset [id] | status | doctor [id] | menu");
|
|
125
132
|
help("fallback", "Using accounts in fallback chains", 'e.g. "agy/claude-opus-5-5": ["agy-acct2/claude-opus-4-6-thinking", …] — a quota error parks one provider/model only');
|
|
126
133
|
help("safety", "Wrong-account protection", "An extra account is used only when agy reports its own token file and the recorded email; otherwise it stops with a sign-in error");
|
|
127
|
-
help("
|
|
134
|
+
help("how", "How it signs in", "Each account runs the real agy CLI (`agy acp`) with that account's own signed-in Google login and folder, the way pi-claude-code runs the Claude Code CLI. pi-agy-bridge never reads or forwards the login.");
|
|
135
|
+
help("apikey", "Optional Gemini API key", "Per account: Enter an account → API key. While a key is set there, that account uses agy's gemini-api-key sign-in (billed per token, Gemini models only); clear it to go back to the Google login. GEMINI_API_KEY from the environment is never used.");
|
|
136
|
+
help("terms", "Terms of service", "Using several accounts and fallback chains across them is your decision for your plan; see Google's Antigravity terms and FAQ");
|
|
137
|
+
help("resume", "Conversation resume", "A continued pi session reattaches to agy's stored conversation (ACP session/resume) instead of re-sending history; PI_AGY_RESUME=0 turns it off");
|
|
128
138
|
|
|
129
139
|
const enabled = views.filter((view) => view.account.enabled).length;
|
|
130
140
|
return {
|
|
@@ -150,7 +160,28 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
|
|
|
150
160
|
items.push({ group: "Actions", id, label, description, value, tone });
|
|
151
161
|
};
|
|
152
162
|
const extra = !view.isDefault;
|
|
153
|
-
|
|
163
|
+
const apiKey = view.auth === "api-key";
|
|
164
|
+
add(
|
|
165
|
+
"apikey",
|
|
166
|
+
apiKey ? "API key (in use)…" : "Use a Gemini API key…",
|
|
167
|
+
apiKey
|
|
168
|
+
? "Replace the key, or enter nothing to remove it and go back to this account's Google login through agy"
|
|
169
|
+
: "Optional: paste a Gemini API key to sign this account in with it instead of its Google login (billed per token, Gemini models only)",
|
|
170
|
+
apiKey ? (view.apiKey?.masked ?? "set") : "not set",
|
|
171
|
+
apiKey ? "ok" : "muted",
|
|
172
|
+
);
|
|
173
|
+
if (apiKey) {
|
|
174
|
+
add(
|
|
175
|
+
"googlelogin",
|
|
176
|
+
"Use agy login (remove API key)",
|
|
177
|
+
extra
|
|
178
|
+
? `Delete the stored key and go back to this account's own agy Google login in accounts/${view.account.id}/gemini (kept untouched)`
|
|
179
|
+
: "Delete the stored key and go back to agy's own Google login",
|
|
180
|
+
extra ? (view.hasGoogleLogin ? "login saved" : "needs sign-in") : "agy login",
|
|
181
|
+
extra && !view.hasGoogleLogin ? "warn" : "ok",
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (extra && !apiKey) {
|
|
154
185
|
add(
|
|
155
186
|
"login",
|
|
156
187
|
view.savedLogin ? "Sign in again (switch Google account)" : "Sign in with Google",
|
|
@@ -158,8 +189,10 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
|
|
|
158
189
|
loginRunning ? "running…" : view.savedLogin ? "signed in" : "required",
|
|
159
190
|
view.savedLogin ? "ok" : "warn",
|
|
160
191
|
);
|
|
161
|
-
add("alias", "Set alias", `Rename the provider to agy-<alias>; the folder stays accounts/${view.account.id}`, view.account.alias ?? "none");
|
|
162
192
|
add("email", "Set expected email", "Normally recorded at sign-in; set by hand only to pin an account", view.account.email ? maskEmail(view.account.email) : "none");
|
|
193
|
+
}
|
|
194
|
+
if (extra) {
|
|
195
|
+
add("alias", "Set alias", `Rename the provider to agy-<alias>; the folder stays accounts/${view.account.id}`, view.account.alias ?? "none");
|
|
163
196
|
add("toggle", view.account.enabled ? "Disable" : "Enable", view.account.enabled ? "Hide its models and stop its process; the login is kept" : "Register its provider again", view.account.enabled ? "enabled" : "disabled", view.account.enabled ? "ok" : "muted");
|
|
164
197
|
}
|
|
165
198
|
if (view.account.enabled) {
|
|
@@ -169,7 +202,13 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
|
|
|
169
202
|
if (view.models) add("models", "Show models", "List the model ids this account offers (for fallback chains)", `${view.models.length}`);
|
|
170
203
|
}
|
|
171
204
|
if (extra && !view.account.fromEnv) add("remove", "Remove account…", "Forget it; optionally delete its saved login and agy data", "CAUTION", "caution");
|
|
172
|
-
if (view.isDefault)
|
|
205
|
+
if (view.isDefault) {
|
|
206
|
+
add(
|
|
207
|
+
"default-help",
|
|
208
|
+
"About the default account",
|
|
209
|
+
apiKey ? "Signs in with the Gemini API key set here; cannot be removed or renamed" : "Uses agy's own login (run `agy` in a terminal to change it); cannot be removed or renamed",
|
|
210
|
+
);
|
|
211
|
+
}
|
|
173
212
|
add("back", "Back", "Return to the account list");
|
|
174
213
|
return {
|
|
175
214
|
title: `pi-agy-bridge · ${view.isDefault ? "agy (default)" : view.provider}`,
|
|
@@ -261,6 +300,33 @@ export async function promptAdd(manager: AccountManager, ctx: Ctx, notify: Notif
|
|
|
261
300
|
return id;
|
|
262
301
|
}
|
|
263
302
|
|
|
303
|
+
/** Ask for a Gemini API key and store it. Returns true when a key was stored, false when the stored key was removed,
|
|
304
|
+
* undefined when cancelled. The key is never echoed back, only a masked preview. */
|
|
305
|
+
export async function promptApiKey(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean | undefined> {
|
|
306
|
+
const raw = await ctx.ui.input(
|
|
307
|
+
`Gemini API key for ${id === DEFAULT_ACCOUNT ? "the default account" : id} (from aistudio.google.com/apikey; empty = remove it and use the Google login)`,
|
|
308
|
+
"AIza…",
|
|
309
|
+
);
|
|
310
|
+
if (raw === undefined) return undefined;
|
|
311
|
+
const value = raw.trim();
|
|
312
|
+
if (value) {
|
|
313
|
+
const problem = validateApiKey(value);
|
|
314
|
+
if (problem) {
|
|
315
|
+
notify(`pi-agy-bridge: ${problem}`, "error");
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
await manager.setApiKey(id, value || undefined);
|
|
320
|
+
const name = id === DEFAULT_ACCOUNT ? "agy" : id;
|
|
321
|
+
notify(
|
|
322
|
+
value
|
|
323
|
+
? `pi-agy-bridge: ${name} now signs in with the API key ${value.slice(0, 4)}…${value.slice(-4)} (Gemini models only, billed per token); its Google login is kept`
|
|
324
|
+
: `pi-agy-bridge: API key removed; ${name} signs in with its Google login through agy again`,
|
|
325
|
+
"info",
|
|
326
|
+
);
|
|
327
|
+
return value ? true : false;
|
|
328
|
+
}
|
|
329
|
+
|
|
264
330
|
export async function promptRemove(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean> {
|
|
265
331
|
if (!(await ctx.ui.confirm(`Remove account "${id}"?`, `Its provider agy-${labelFor(manager.accounts.find((a) => a.id === id) ?? { id })} disappears from pi.`))) return false;
|
|
266
332
|
const deleteLogin = await ctx.ui.confirm(
|
|
@@ -427,6 +493,25 @@ export async function runAccountAction(
|
|
|
427
493
|
if (!view) throw new Error(`no account "${id}"`);
|
|
428
494
|
const provider = view.isDefault ? "agy" : view.provider;
|
|
429
495
|
switch (action) {
|
|
496
|
+
case "googlelogin": {
|
|
497
|
+
if (view.auth !== "api-key") {
|
|
498
|
+
notify(`pi-agy-bridge: ${provider} already uses its agy Google login`, "info");
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
if (ctx.hasUI && !(await ctx.ui.confirm("Use agy login?", `Delete ${provider}'s stored API key and sign in with its agy Google login again?`))) break;
|
|
502
|
+
await manager.setApiKey(id, undefined);
|
|
503
|
+
const back = (await manager.views()).find((entry) => entry.account.id === id);
|
|
504
|
+
if (!view.isDefault && back && !back.savedLogin) {
|
|
505
|
+
notify(`pi-agy-bridge: API key removed; ${provider} has no saved agy login yet — run /agy-bridge login ${id}`, "warning");
|
|
506
|
+
} else {
|
|
507
|
+
const check = await manager.check(id);
|
|
508
|
+
notify(`pi-agy-bridge: API key removed; ${check.message}`, check.ok ? "info" : "warning");
|
|
509
|
+
}
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
case "apikey":
|
|
513
|
+
await promptApiKey(manager, id, ctx, notify);
|
|
514
|
+
break;
|
|
430
515
|
case "login":
|
|
431
516
|
await runLogin(manager, id, ctx, notify);
|
|
432
517
|
break;
|