@timmyjl12/pi-agy-bridge 0.3.2 → 0.4.1
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 +15 -3
- package/README.md +7 -4
- 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 +46 -2
- package/src/accounts.ts +94 -4
- package/src/acp/connection.ts +17 -1
- package/src/config.ts +6 -0
- package/src/conversation-store.ts +168 -0
- package/src/errors.ts +2 -2
- package/src/index.ts +10 -2
- package/src/model-catalog.ts +48 -2
- package/src/provider.ts +10 -4
- package/src/runtime.ts +106 -9
- package/src/session-pool.ts +178 -7
- package/src/stream.ts +93 -13
- package/src/ui/menu.ts +69 -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,17 @@ 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 (extra && !apiKey) {
|
|
154
174
|
add(
|
|
155
175
|
"login",
|
|
156
176
|
view.savedLogin ? "Sign in again (switch Google account)" : "Sign in with Google",
|
|
@@ -158,8 +178,10 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
|
|
|
158
178
|
loginRunning ? "running…" : view.savedLogin ? "signed in" : "required",
|
|
159
179
|
view.savedLogin ? "ok" : "warn",
|
|
160
180
|
);
|
|
161
|
-
add("alias", "Set alias", `Rename the provider to agy-<alias>; the folder stays accounts/${view.account.id}`, view.account.alias ?? "none");
|
|
162
181
|
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");
|
|
182
|
+
}
|
|
183
|
+
if (extra) {
|
|
184
|
+
add("alias", "Set alias", `Rename the provider to agy-<alias>; the folder stays accounts/${view.account.id}`, view.account.alias ?? "none");
|
|
163
185
|
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
186
|
}
|
|
165
187
|
if (view.account.enabled) {
|
|
@@ -169,7 +191,13 @@ export function accountActionsView(view: AccountView, loginRunning: boolean): Pa
|
|
|
169
191
|
if (view.models) add("models", "Show models", "List the model ids this account offers (for fallback chains)", `${view.models.length}`);
|
|
170
192
|
}
|
|
171
193
|
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)
|
|
194
|
+
if (view.isDefault) {
|
|
195
|
+
add(
|
|
196
|
+
"default-help",
|
|
197
|
+
"About the default account",
|
|
198
|
+
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",
|
|
199
|
+
);
|
|
200
|
+
}
|
|
173
201
|
add("back", "Back", "Return to the account list");
|
|
174
202
|
return {
|
|
175
203
|
title: `pi-agy-bridge · ${view.isDefault ? "agy (default)" : view.provider}`,
|
|
@@ -261,6 +289,33 @@ export async function promptAdd(manager: AccountManager, ctx: Ctx, notify: Notif
|
|
|
261
289
|
return id;
|
|
262
290
|
}
|
|
263
291
|
|
|
292
|
+
/** Ask for a Gemini API key and store it. Returns true when a key was stored, false when the stored key was removed,
|
|
293
|
+
* undefined when cancelled. The key is never echoed back, only a masked preview. */
|
|
294
|
+
export async function promptApiKey(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean | undefined> {
|
|
295
|
+
const raw = await ctx.ui.input(
|
|
296
|
+
`Gemini API key for ${id === DEFAULT_ACCOUNT ? "the default account" : id} (from aistudio.google.com/apikey; empty = remove it and use the Google login)`,
|
|
297
|
+
"AIza…",
|
|
298
|
+
);
|
|
299
|
+
if (raw === undefined) return undefined;
|
|
300
|
+
const value = raw.trim();
|
|
301
|
+
if (value) {
|
|
302
|
+
const problem = validateApiKey(value);
|
|
303
|
+
if (problem) {
|
|
304
|
+
notify(`pi-agy-bridge: ${problem}`, "error");
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
await manager.setApiKey(id, value || undefined);
|
|
309
|
+
const name = id === DEFAULT_ACCOUNT ? "agy" : id;
|
|
310
|
+
notify(
|
|
311
|
+
value
|
|
312
|
+
? `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`
|
|
313
|
+
: `pi-agy-bridge: API key removed; ${name} signs in with its Google login through agy again`,
|
|
314
|
+
"info",
|
|
315
|
+
);
|
|
316
|
+
return value ? true : false;
|
|
317
|
+
}
|
|
318
|
+
|
|
264
319
|
export async function promptRemove(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean> {
|
|
265
320
|
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
321
|
const deleteLogin = await ctx.ui.confirm(
|
|
@@ -427,6 +482,9 @@ export async function runAccountAction(
|
|
|
427
482
|
if (!view) throw new Error(`no account "${id}"`);
|
|
428
483
|
const provider = view.isDefault ? "agy" : view.provider;
|
|
429
484
|
switch (action) {
|
|
485
|
+
case "apikey":
|
|
486
|
+
await promptApiKey(manager, id, ctx, notify);
|
|
487
|
+
break;
|
|
430
488
|
case "login":
|
|
431
489
|
await runLogin(manager, id, ctx, notify);
|
|
432
490
|
break;
|