@timmyjl12/pi-agy-bridge 0.1.4 → 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/ARCHITECTURE.md +11 -1
- package/README.md +53 -8
- package/UPGRADING.md +133 -111
- package/compat/baselines/agy-1.5.12.json +259 -0
- package/compat/baselines/agy-1.5.14.json +260 -0
- package/compat/matrix.json +1 -1
- package/compat/probe.ts +71 -2
- package/compat/sdk-canary/canary.py +9 -3
- package/package.json +4 -2
- package/src/account-manager.ts +397 -0
- package/src/accounts.ts +349 -0
- package/src/acp/connection.ts +1 -1
- package/src/config.ts +6 -0
- package/src/doctor.ts +13 -3
- package/src/index.ts +199 -25
- package/src/model-catalog.ts +19 -6
- package/src/provider.ts +30 -8
- package/src/runtime.ts +133 -6
- package/src/session-pool.ts +88 -6
- package/src/stream.ts +41 -8
- package/src/ui/menu.ts +440 -0
- package/src/ui/panel.ts +376 -0
package/src/ui/menu.ts
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// /agy-bridge menu: a comprehensive management overlay for accounts, processes and diagnostics.
|
|
2
|
+
//
|
|
3
|
+
// Every action here calls the same AccountManager / runtime function as its `/agy-bridge` subcommand, so the menu and
|
|
4
|
+
// the commands can never drift. In a non-TUI host (RPC, print) the same actions run through ui.select/input/confirm.
|
|
5
|
+
|
|
6
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { DEFAULT_ACCOUNT, labelFor, maskEmail, validateAccountName } from "../accounts.ts";
|
|
8
|
+
import type { AccountManager, AccountView } from "../account-manager.ts";
|
|
9
|
+
import { buildDoctor, buildStatus } from "../doctor.ts";
|
|
10
|
+
import { CONFIG_ENV_NAMES } from "../config.ts";
|
|
11
|
+
import { describeError } from "../errors.ts";
|
|
12
|
+
import { showPanel, type PanelItem, type PanelView } from "./panel.ts";
|
|
13
|
+
|
|
14
|
+
export type Notify = (message: string, level: "info" | "warning" | "error") => void;
|
|
15
|
+
|
|
16
|
+
type Ctx = Pick<ExtensionCommandContext, "ui" | "mode" | "hasUI">;
|
|
17
|
+
|
|
18
|
+
const GROUPS = ["Accounts", "Add account", "Processes", "Diagnostics", "Settings", "Help"] as const;
|
|
19
|
+
|
|
20
|
+
export function stateOf(view: AccountView): { text: string; tone: PanelItem["tone"] } {
|
|
21
|
+
if (!view.account.enabled) return { text: "disabled", tone: "muted" };
|
|
22
|
+
if (view.identity && !view.identity.ok) return { text: "sign-in problem", tone: "error" };
|
|
23
|
+
if (!view.isDefault && !view.savedLogin) return { text: "not signed in", tone: "warn" };
|
|
24
|
+
if (view.running) return { text: `running · ${view.models?.length ?? "?"} models`, tone: "ok" };
|
|
25
|
+
if (view.models) return { text: `ready · ${view.models.length} models`, tone: "ok" };
|
|
26
|
+
return { text: "ready", tone: "normal" };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function emailOf(view: AccountView): string | undefined {
|
|
30
|
+
return view.identity?.email ?? view.account.email;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function accountDetail(view: AccountView): string[] {
|
|
34
|
+
const lines: string[] = [];
|
|
35
|
+
const email = emailOf(view);
|
|
36
|
+
lines.push(
|
|
37
|
+
`provider ${view.provider} · ${view.isDefault ? "Windows/OS keyring login (agy's own)" : "own token file"}` +
|
|
38
|
+
` · account ${email ? maskEmail(email) : view.isDefault ? "(agy's signed-in user)" : "not recorded"}` +
|
|
39
|
+
(view.tier ? ` · ${view.tier}` : ""),
|
|
40
|
+
);
|
|
41
|
+
lines.push(
|
|
42
|
+
`process ${view.running ? `running (pid ${view.pid ?? "?"})` : "stopped"} · sessions ${view.sessions.idle} reusable / ${view.sessions.busy} busy` +
|
|
43
|
+
(view.agyVersion ? ` · agy ${view.agyVersion}` : ""),
|
|
44
|
+
);
|
|
45
|
+
if (view.identity && !view.identity.ok) lines.push(`last check: ${view.identity.message ?? "failed"}`);
|
|
46
|
+
else if (view.models) lines.push(`models: ${view.models.join(", ")}`);
|
|
47
|
+
else lines.push("models: not discovered yet — choose “Check now” to start this account once (no prompt, no quota)");
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MenuDeps {
|
|
52
|
+
manager: AccountManager;
|
|
53
|
+
notify: Notify;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Build the main menu view from the current account state. Pure apart from reading the manager. */
|
|
57
|
+
export async function mainView(manager: AccountManager, activeGroup?: string): Promise<{ view: PanelView; views: AccountView[] }> {
|
|
58
|
+
await manager.load();
|
|
59
|
+
const views = await manager.views();
|
|
60
|
+
const items: PanelItem[] = [];
|
|
61
|
+
const add = (item: PanelItem): void => {
|
|
62
|
+
items.push(item);
|
|
63
|
+
};
|
|
64
|
+
for (const view of views) {
|
|
65
|
+
const state = stateOf(view);
|
|
66
|
+
const email = emailOf(view);
|
|
67
|
+
add({
|
|
68
|
+
group: "Accounts",
|
|
69
|
+
id: `account:${view.account.id}`,
|
|
70
|
+
label: `${view.isDefault ? "agy" : view.provider} ${view.isDefault ? "(default)" : view.account.alias ? `(${view.account.id})` : ""}`.trim(),
|
|
71
|
+
value: state.text,
|
|
72
|
+
tone: state.tone,
|
|
73
|
+
description: `${email ? maskEmail(email) : view.isDefault ? "agy's own login" : "no account recorded"} · Enter for actions: sign in, alias, enable/disable, check, reset, remove`,
|
|
74
|
+
search: `${view.account.id} ${view.account.alias ?? ""} ${email ?? ""} ${view.provider}`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
add({ group: "Accounts", id: "check-all", label: "Check every account now", description: "Start each enabled account once and list its models (no prompt, no quota)" });
|
|
78
|
+
|
|
79
|
+
add({
|
|
80
|
+
group: "Add account",
|
|
81
|
+
id: "add",
|
|
82
|
+
label: "Add an Antigravity account…",
|
|
83
|
+
description: "Choose a short id (e.g. acct2), optionally an alias, then sign in with Google in the browser",
|
|
84
|
+
});
|
|
85
|
+
add({
|
|
86
|
+
group: "Add account",
|
|
87
|
+
id: "add-help",
|
|
88
|
+
label: "How extra accounts work",
|
|
89
|
+
description: "Each account runs its own agy process with its own login; pi lists it as provider agy-<alias or id>",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
for (const view of views) {
|
|
93
|
+
if (!view.account.enabled) continue;
|
|
94
|
+
add({
|
|
95
|
+
group: "Processes",
|
|
96
|
+
id: `reset:${view.account.id}`,
|
|
97
|
+
label: `Reset ${view.isDefault ? "agy" : view.provider}`,
|
|
98
|
+
value: view.running ? `pid ${view.pid ?? "?"} · ${view.sessions.idle + view.sessions.busy} sessions` : "stopped",
|
|
99
|
+
tone: view.running ? "ok" : "muted",
|
|
100
|
+
description: "Stop this account's agy process and forget its pooled sessions; the next request starts fresh",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
add({ group: "Processes", id: "reset-all", label: "Reset every account", tone: "caution", value: "all", description: "Stop all agy processes started by this extension" });
|
|
104
|
+
|
|
105
|
+
add({ group: "Diagnostics", id: "status", label: "Status line", description: "One line per account: version, process, sessions" });
|
|
106
|
+
add({ group: "Diagnostics", id: "doctor", label: "Doctor (default account)", description: "Handshake, compatibility report and model list for agy" });
|
|
107
|
+
for (const view of views.filter((entry) => !entry.isDefault && entry.account.enabled)) {
|
|
108
|
+
add({ group: "Diagnostics", id: `doctor:${view.account.id}`, label: `Doctor · ${view.provider}`, description: "Same report for this account's own process" });
|
|
109
|
+
}
|
|
110
|
+
for (const warning of manager.warnings) add({ group: "Diagnostics", id: `warning:${items.length}`, label: "Configuration warning", value: "!", tone: "warn", description: warning });
|
|
111
|
+
|
|
112
|
+
const config = manager.default.config;
|
|
113
|
+
const setting = (id: string, label: string, value: string, description: string): void => add({ group: "Settings", id: `setting:${id}`, label, value, description });
|
|
114
|
+
setting("home", "State folder", config.home, "PI_AGY_HOME — accounts live in <home>/accounts/<id>");
|
|
115
|
+
setting("command", "agy executable", config.command, "PI_AGY_COMMAND / AGY_BIN");
|
|
116
|
+
setting("idle", "Idle process exit", `${Math.round(config.idleExitMs / 60_000)} min`, "PI_AGY_IDLE_MIN — each account's process stops after this long unused");
|
|
117
|
+
setting("sessions", "Pooled sessions per account", String(config.maxSessions), "PI_AGY_MAX_SESSIONS");
|
|
118
|
+
setting("system", "System prompt delivery", config.systemPrompt, "PI_AGY_SYSTEM_PROMPT: auto | append | inline");
|
|
119
|
+
setting("env", "Environment settings", `${CONFIG_ENV_NAMES.length} variables`, `Set in the environment or pi's provider env: ${CONFIG_ENV_NAMES.join(", ")}, PI_AGY_ACCOUNTS`);
|
|
120
|
+
|
|
121
|
+
const help = (id: string, label: string, description: string): void => add({ group: "Help", id: `help:${id}`, label, description });
|
|
122
|
+
help("keys", "Keys", "↑↓ move · ←→ pane · Tab section · / search all · Enter select · Esc back/close");
|
|
123
|
+
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");
|
|
124
|
+
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');
|
|
125
|
+
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");
|
|
126
|
+
help("terms", "Terms of service", "Whether using several Google accounts is allowed for your plan is your decision");
|
|
127
|
+
|
|
128
|
+
const enabled = views.filter((view) => view.account.enabled).length;
|
|
129
|
+
return {
|
|
130
|
+
views,
|
|
131
|
+
view: {
|
|
132
|
+
title: "pi-agy-bridge · accounts & settings",
|
|
133
|
+
subtitle: `${enabled} active account${enabled === 1 ? "" : "s"} · ${buildStatus(manager.default)}`,
|
|
134
|
+
groups: GROUPS,
|
|
135
|
+
items,
|
|
136
|
+
activeGroup: activeGroup ?? "Accounts",
|
|
137
|
+
detail: (item) => {
|
|
138
|
+
const id = item.id.startsWith("account:") ? item.id.slice(8) : undefined;
|
|
139
|
+
const view = id ? views.find((entry) => entry.account.id === id) : undefined;
|
|
140
|
+
return view ? accountDetail(view) : [];
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function accountActionsView(view: AccountView, loginRunning: boolean): PanelView {
|
|
147
|
+
const items: PanelItem[] = [];
|
|
148
|
+
const add = (id: string, label: string, description: string, value?: string, tone?: PanelItem["tone"]): void => {
|
|
149
|
+
items.push({ group: "Actions", id, label, description, value, tone });
|
|
150
|
+
};
|
|
151
|
+
const extra = !view.isDefault;
|
|
152
|
+
if (extra) {
|
|
153
|
+
add(
|
|
154
|
+
"login",
|
|
155
|
+
view.savedLogin ? "Sign in again (switch Google account)" : "Sign in with Google",
|
|
156
|
+
"Opens the browser through agy; the new email becomes this account's expected identity",
|
|
157
|
+
loginRunning ? "running…" : view.savedLogin ? "signed in" : "required",
|
|
158
|
+
view.savedLogin ? "ok" : "warn",
|
|
159
|
+
);
|
|
160
|
+
add("alias", "Set alias", `Rename the provider to agy-<alias>; the folder stays accounts/${view.account.id}`, view.account.alias ?? "none");
|
|
161
|
+
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");
|
|
162
|
+
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");
|
|
163
|
+
}
|
|
164
|
+
if (view.account.enabled) {
|
|
165
|
+
add("check", "Check now", "Start this account's process and list its models (no prompt, no quota)");
|
|
166
|
+
add("reset", "Reset process", "Stop its agy process and forget pooled sessions", view.running ? `pid ${view.pid ?? "?"}` : "stopped");
|
|
167
|
+
add("doctor", "Doctor report", "Full compatibility and model report for this account");
|
|
168
|
+
if (view.models) add("models", "Show models", "List the model ids this account offers (for fallback chains)", `${view.models.length}`);
|
|
169
|
+
}
|
|
170
|
+
if (extra && !view.account.fromEnv) add("remove", "Remove account…", "Forget it; optionally delete its saved login and agy data", "CAUTION", "caution");
|
|
171
|
+
if (view.isDefault) add("default-help", "About the default account", "Uses agy's own login (run `agy` in a terminal to change it); cannot be removed or renamed");
|
|
172
|
+
add("back", "Back", "Return to the account list");
|
|
173
|
+
return {
|
|
174
|
+
title: `pi-agy-bridge · ${view.isDefault ? "agy (default)" : view.provider}`,
|
|
175
|
+
subtitle: accountDetail(view)[0] ?? "",
|
|
176
|
+
groups: ["Actions"],
|
|
177
|
+
items,
|
|
178
|
+
activeGroup: "Actions",
|
|
179
|
+
detail: () => accountDetail(view),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ---- actions (shared with commands) ------------------------------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
export async function runLogin(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean> {
|
|
186
|
+
notify(`pi-agy-bridge: signing in account "${id}" — finish the Google sign-in in your browser (up to 5 min)…`, "info");
|
|
187
|
+
let urlShown = false;
|
|
188
|
+
const result = await manager.login(id, (progress) => {
|
|
189
|
+
if (progress.url && !urlShown) {
|
|
190
|
+
urlShown = true;
|
|
191
|
+
notify(`pi-agy-bridge: if no browser opened, visit: ${progress.url}`, "info");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
notify(`pi-agy-bridge: ${id}: ${result.message}`, result.ok ? "info" : "error");
|
|
195
|
+
if (result.ok) {
|
|
196
|
+
const check = await manager.check(id);
|
|
197
|
+
notify(`pi-agy-bridge: ${check.message}`, check.ok ? "info" : "warning");
|
|
198
|
+
}
|
|
199
|
+
return result.ok;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export async function promptAdd(manager: AccountManager, ctx: Ctx, notify: Notify): Promise<string | undefined> {
|
|
203
|
+
const suggested = `acct${manager.accounts.length + 2}`;
|
|
204
|
+
const raw = await ctx.ui.input("New account id (folder name; a-z, 0-9, '-')", suggested);
|
|
205
|
+
if (raw === undefined) return undefined;
|
|
206
|
+
const id = (raw.trim() || suggested).toLowerCase();
|
|
207
|
+
const problem = validateAccountName(id, "id");
|
|
208
|
+
if (problem) {
|
|
209
|
+
notify(`pi-agy-bridge: ${problem}`, "error");
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
const aliasRaw = await ctx.ui.input(`Alias for ${id} (optional; provider becomes agy-<alias>)`, "");
|
|
213
|
+
if (aliasRaw === undefined) return undefined;
|
|
214
|
+
try {
|
|
215
|
+
const account = await manager.add(id, aliasRaw.trim().toLowerCase() || undefined);
|
|
216
|
+
notify(`pi-agy-bridge: added account "${account.id}" as provider agy-${account.alias ?? account.id}`, "info");
|
|
217
|
+
} catch (error) {
|
|
218
|
+
notify(`pi-agy-bridge: ${describeError(error)}`, "error");
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
if (await ctx.ui.confirm("Sign in now?", `Open the Google sign-in for "${id}" in your browser now?`)) await runLogin(manager, id, ctx, notify);
|
|
222
|
+
else notify(`pi-agy-bridge: sign in later with /agy-bridge login ${id}`, "info");
|
|
223
|
+
return id;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function promptRemove(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<boolean> {
|
|
227
|
+
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;
|
|
228
|
+
const deleteLogin = await ctx.ui.confirm(
|
|
229
|
+
"Also delete its saved login?",
|
|
230
|
+
`Delete ${manager.folderOf(id)} (saved Google login and agy data)? Choose No to keep it for re-adding later.`,
|
|
231
|
+
);
|
|
232
|
+
try {
|
|
233
|
+
await manager.remove(id, deleteLogin);
|
|
234
|
+
notify(`pi-agy-bridge: removed account "${id}"${deleteLogin ? " and its saved login" : " (login kept on disk)"}`, "info");
|
|
235
|
+
return true;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
notify(`pi-agy-bridge: ${describeError(error)}`, "error");
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export async function doctorText(manager: AccountManager, id: string): Promise<{ ok: boolean; text: string }> {
|
|
243
|
+
const runtime = manager.runtimeFor(id);
|
|
244
|
+
if (!runtime) return { ok: false, text: `pi-agy-bridge: account "${id}" is not active` };
|
|
245
|
+
const report = await buildDoctor(runtime, { force: true });
|
|
246
|
+
return { ok: report.ok, text: report.lines.join("\n") };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export async function statusText(manager: AccountManager): Promise<string> {
|
|
250
|
+
await manager.load();
|
|
251
|
+
const views = await manager.views();
|
|
252
|
+
return views
|
|
253
|
+
.map((view) => {
|
|
254
|
+
const runtime = manager.runtimeFor(view.account.id);
|
|
255
|
+
const state = stateOf(view).text;
|
|
256
|
+
const email = emailOf(view);
|
|
257
|
+
const head = `${view.isDefault ? "agy" : view.provider}${email ? ` (${maskEmail(email)})` : ""}: ${state}`;
|
|
258
|
+
return runtime ? `${head} — ${buildStatus(runtime)}` : head;
|
|
259
|
+
})
|
|
260
|
+
.join("\n");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function accountPage(manager: AccountManager, id: string, ctx: Ctx, notify: Notify): Promise<void> {
|
|
264
|
+
while (true) {
|
|
265
|
+
await manager.load();
|
|
266
|
+
const view = (await manager.views()).find((entry) => entry.account.id === id);
|
|
267
|
+
if (!view) return;
|
|
268
|
+
const picked = await showPanel(ctx.ui.custom, accountActionsView(view, manager.loginRunning(id)));
|
|
269
|
+
if (picked === null || picked === "back") return;
|
|
270
|
+
try {
|
|
271
|
+
if ((await runAccountAction(manager, id, picked, ctx, notify)) === "removed") return;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
notify(`pi-agy-bridge: ${describeError(error)}`, "error");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** The overlay menu. Falls back to plain dialogs outside the TUI. */
|
|
279
|
+
export async function runMenu(deps: MenuDeps, ctx: Ctx, initialGroup?: string): Promise<void> {
|
|
280
|
+
const { manager, notify } = deps;
|
|
281
|
+
if (ctx.mode !== "tui" || typeof ctx.ui.custom !== "function") {
|
|
282
|
+
await runFallbackMenu(deps, ctx);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
let group = initialGroup;
|
|
286
|
+
while (true) {
|
|
287
|
+
const { view } = await mainView(manager, group);
|
|
288
|
+
const picked = await showPanel(ctx.ui.custom, view);
|
|
289
|
+
if (picked === null) return;
|
|
290
|
+
group = view.items.find((item) => item.id === picked)?.group ?? group;
|
|
291
|
+
try {
|
|
292
|
+
await dispatch(picked, deps, ctx, (id) => accountPage(manager, id, ctx, notify));
|
|
293
|
+
} catch (error) {
|
|
294
|
+
notify(`pi-agy-bridge: ${describeError(error)}`, "error");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function dispatch(picked: string, deps: MenuDeps, ctx: Ctx, openAccount: (id: string) => Promise<void>): Promise<void> {
|
|
300
|
+
const { manager, notify } = deps;
|
|
301
|
+
const [kind, arg] = picked.split(/:(.*)/s, 2);
|
|
302
|
+
switch (kind) {
|
|
303
|
+
case "account":
|
|
304
|
+
if (arg) await openAccount(arg);
|
|
305
|
+
return;
|
|
306
|
+
case "add":
|
|
307
|
+
await promptAdd(manager, ctx, notify);
|
|
308
|
+
return;
|
|
309
|
+
case "add-help":
|
|
310
|
+
notify(
|
|
311
|
+
"Each extra account gets its own folder, its own agy process and its own Google login (saved by agy in a file inside that folder). pi lists it as provider agy-<alias or id> with the models that account offers. Your default `agy` account is unchanged.",
|
|
312
|
+
"info",
|
|
313
|
+
);
|
|
314
|
+
return;
|
|
315
|
+
case "check-all":
|
|
316
|
+
for (const view of await manager.views()) {
|
|
317
|
+
if (!view.account.enabled) continue;
|
|
318
|
+
const result = await manager.check(view.account.id);
|
|
319
|
+
notify(`pi-agy-bridge: ${result.message}`, result.ok ? "info" : "warning");
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
case "reset":
|
|
323
|
+
if (arg) {
|
|
324
|
+
await manager.reset(arg);
|
|
325
|
+
notify(`pi-agy-bridge: ${arg === DEFAULT_ACCOUNT ? "agy" : arg} reset`, "info");
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
case "reset-all":
|
|
329
|
+
if (await ctx.ui.confirm("Reset every account?", "Stop all agy processes and forget pooled sessions?")) {
|
|
330
|
+
await manager.resetAll();
|
|
331
|
+
notify("pi-agy-bridge: every agy process reset", "info");
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
case "status":
|
|
335
|
+
notify(await statusText(manager), "info");
|
|
336
|
+
return;
|
|
337
|
+
case "doctor": {
|
|
338
|
+
const report = await doctorText(manager, arg ?? DEFAULT_ACCOUNT);
|
|
339
|
+
notify(report.text, report.ok ? "info" : "error");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
default: {
|
|
343
|
+
const item = (await mainView(manager)).view.items.find((entry) => entry.id === picked);
|
|
344
|
+
if (item) notify(`${item.label}${item.value ? `: ${item.value}` : ""} — ${item.description}`, "info");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function runFallbackMenu(deps: MenuDeps, ctx: Ctx): Promise<void> {
|
|
350
|
+
const { manager, notify } = deps;
|
|
351
|
+
if (!ctx.hasUI) {
|
|
352
|
+
notify(await statusText(manager), "info");
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
while (true) {
|
|
356
|
+
const { view } = await mainView(manager);
|
|
357
|
+
const choices = view.items.filter((item) => !item.heading);
|
|
358
|
+
const labels = choices.map((item) => `${item.group} › ${item.label}${item.value ? ` [${item.value}]` : ""}`);
|
|
359
|
+
const picked = await ctx.ui.select("pi-agy-bridge", [...labels, "Close"]);
|
|
360
|
+
if (!picked || picked === "Close") return;
|
|
361
|
+
const item = choices[labels.indexOf(picked)];
|
|
362
|
+
if (!item) return;
|
|
363
|
+
try {
|
|
364
|
+
await dispatch(item.id, deps, ctx, async (id) => {
|
|
365
|
+
const account = (await manager.views()).find((entry) => entry.account.id === id);
|
|
366
|
+
if (!account) return;
|
|
367
|
+
const actions = accountActionsView(account, manager.loginRunning(id)).items;
|
|
368
|
+
const actionLabels = actions.map((action) => action.label);
|
|
369
|
+
const action = await ctx.ui.select(`pi-agy-bridge · ${account.provider}`, actionLabels);
|
|
370
|
+
const chosen = actions[actionLabels.indexOf(action ?? "")];
|
|
371
|
+
if (!chosen || chosen.id === "back") return;
|
|
372
|
+
await runAccountAction(manager, id, chosen.id, ctx, notify);
|
|
373
|
+
});
|
|
374
|
+
} catch (error) {
|
|
375
|
+
notify(`pi-agy-bridge: ${describeError(error)}`, "error");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** One account action by id: the single implementation behind the account page, the non-TUI menu and commands. */
|
|
381
|
+
export async function runAccountAction(
|
|
382
|
+
manager: AccountManager,
|
|
383
|
+
id: string,
|
|
384
|
+
action: string,
|
|
385
|
+
ctx: Ctx,
|
|
386
|
+
notify: Notify,
|
|
387
|
+
): Promise<"done" | "removed"> {
|
|
388
|
+
const view = (await manager.views()).find((entry) => entry.account.id === id);
|
|
389
|
+
if (!view) throw new Error(`no account "${id}"`);
|
|
390
|
+
const provider = view.isDefault ? "agy" : view.provider;
|
|
391
|
+
switch (action) {
|
|
392
|
+
case "login":
|
|
393
|
+
await runLogin(manager, id, ctx, notify);
|
|
394
|
+
break;
|
|
395
|
+
case "alias": {
|
|
396
|
+
const value = await ctx.ui.input(`Alias for ${id} (empty = none; provider becomes agy-<alias>)`, view.account.alias ?? "");
|
|
397
|
+
if (value === undefined) break;
|
|
398
|
+
const next = await manager.setAlias(id, value);
|
|
399
|
+
notify(`pi-agy-bridge: ${id} is now provider agy-${next.alias ?? next.id}`, "info");
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
case "email": {
|
|
403
|
+
const value = await ctx.ui.input(`Expected Google account for ${id} (empty = clear)`, view.account.email ?? "");
|
|
404
|
+
if (value === undefined) break;
|
|
405
|
+
await manager.setEmail(id, value);
|
|
406
|
+
notify(`pi-agy-bridge: expected account for ${id}: ${value.trim() ? maskEmail(value.trim()) : "cleared"}`, "info");
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case "toggle":
|
|
410
|
+
await manager.setEnabled(id, !view.account.enabled);
|
|
411
|
+
notify(`pi-agy-bridge: ${id} ${view.account.enabled ? "disabled" : "enabled"}`, "info");
|
|
412
|
+
break;
|
|
413
|
+
case "check": {
|
|
414
|
+
const result = await manager.check(id);
|
|
415
|
+
notify(`pi-agy-bridge: ${result.message}`, result.ok ? "info" : "error");
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case "reset":
|
|
419
|
+
await manager.reset(id);
|
|
420
|
+
notify(`pi-agy-bridge: ${provider} reset`, "info");
|
|
421
|
+
break;
|
|
422
|
+
case "doctor": {
|
|
423
|
+
const report = await doctorText(manager, id);
|
|
424
|
+
notify(report.text, report.ok ? "info" : "error");
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case "models":
|
|
428
|
+
notify(
|
|
429
|
+
view.models ? `${provider} models:\n${view.models.map((model) => ` ${provider}/${model}`).join("\n")}` : `${provider}: no models discovered yet`,
|
|
430
|
+
"info",
|
|
431
|
+
);
|
|
432
|
+
break;
|
|
433
|
+
case "remove":
|
|
434
|
+
return (await promptRemove(manager, id, ctx, notify)) ? "removed" : "done";
|
|
435
|
+
case "default-help":
|
|
436
|
+
notify("The default account is agy's own login (OS keyring). Run `agy` in a terminal and use /logout there to switch it.", "info");
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
return "done";
|
|
440
|
+
}
|