@av-pi-studio/cli 0.0.70 → 0.0.72
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/README.md +40 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/auth-commands.d.ts +43 -0
- package/dist/auth-commands.d.ts.map +1 -0
- package/dist/auth-commands.js +301 -0
- package/dist/auth-commands.js.map +1 -0
- package/dist/auth-interaction.d.ts +81 -0
- package/dist/auth-interaction.d.ts.map +1 -0
- package/dist/auth-interaction.js +251 -0
- package/dist/auth-interaction.js.map +1 -0
- package/dist/auth-runtime.d.ts +119 -0
- package/dist/auth-runtime.d.ts.map +1 -0
- package/dist/auth-runtime.js +90 -0
- package/dist/auth-runtime.js.map +1 -0
- package/dist/cli-core.d.ts +3 -0
- package/dist/cli-core.d.ts.map +1 -1
- package/dist/cli-core.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +2 -0
- package/dist/program.js.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type TerminalIo } from "./auth-interaction.js";
|
|
3
|
+
import { type AuthRuntime, type AuthStatusInfo } from "./auth-runtime.js";
|
|
4
|
+
import { type CliContext, type GlobalOptions } from "./cli-core.js";
|
|
5
|
+
/**
|
|
6
|
+
* `auth` command group (features/provider-auth-cli.md § Public Contract — Commands table,
|
|
7
|
+
* § Behavior — status/logout/login, § Error Handling). Never opens a WebSocket — these commands
|
|
8
|
+
* talk directly to Pi's local auth store through the task-001 `AuthRuntime` seam.
|
|
9
|
+
*/
|
|
10
|
+
/** Bounded per-provider checkAuth probe; shared with task 004's provider picker. */
|
|
11
|
+
export declare const CHECK_AUTH_TIMEOUT_MS = 3000;
|
|
12
|
+
/**
|
|
13
|
+
* Probe one provider's auth status with a bounded timeout. A hang (e.g. a slow ambient probe:
|
|
14
|
+
* an AWS-profile or ADC-file check) degrades to `"unknown"` rather than blocking the whole
|
|
15
|
+
* command — or, for task 004, the provider picker.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkAuthBounded(runtime: AuthRuntime, providerId: string, timeoutMs?: number): Promise<AuthStatusInfo | "unknown">;
|
|
18
|
+
/** Row shape shared by table and JSON rendering. */
|
|
19
|
+
export interface AuthStatusRow {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
configured: boolean | "unknown";
|
|
23
|
+
type?: "api_key" | "oauth";
|
|
24
|
+
source?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `auth login [provider] [--type api_key|oauth] [--api-key K]` (features/provider-auth-cli.md
|
|
28
|
+
* § Behavior & Algorithms — `authLogin`, § Error Handling & Edge Cases). Exported so tests can
|
|
29
|
+
* drive it directly with a fake `TerminalIo`, bypassing Commander. `io` is left unresolved (no
|
|
30
|
+
* default-parameter expression) until *after* the flow's `AbortController` exists —
|
|
31
|
+
* `createTerminalIo()` needs it to map inquirer's Ctrl+C rejection (`ExitPromptError`) to a flow
|
|
32
|
+
* abort (inquirer traps SIGINT itself while a prompt is live; see auth-interaction.ts) — and only
|
|
33
|
+
* when the caller omits `io` at all and the flow actually needs terminal I/O (never for
|
|
34
|
+
* `--api-key`, which uses a prefilled interaction instead), so no prompt machinery — and no Pi
|
|
35
|
+
* import further down the call chain — is created at module load, registration, pre-flight-error,
|
|
36
|
+
* or headless-login time.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runAuthLogin(ctx: CliContext, opts: GlobalOptions, providerArg: string | undefined, cmdOpts: {
|
|
39
|
+
type?: string;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
}, io?: TerminalIo): Promise<number>;
|
|
42
|
+
export declare function registerAuthCommands(program: Command, ctx: CliContext, setExit: (code: number) => void): void;
|
|
43
|
+
//# sourceMappingURL=auth-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-commands.d.ts","sourceRoot":"","sources":["../src/auth-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ApiKeyInteraction, createTerminalIo, createTerminalInteraction, } from "./auth-interaction.js";
|
|
2
|
+
import { defaultAuthRuntime, resolvePiAuthPaths, } from "./auth-runtime.js";
|
|
3
|
+
import { EXIT_ERROR, EXIT_OK, errorMessage, } from "./cli-core.js";
|
|
4
|
+
import { renderTable } from "./output.js";
|
|
5
|
+
/**
|
|
6
|
+
* `auth` command group (features/provider-auth-cli.md § Public Contract — Commands table,
|
|
7
|
+
* § Behavior — status/logout/login, § Error Handling). Never opens a WebSocket — these commands
|
|
8
|
+
* talk directly to Pi's local auth store through the task-001 `AuthRuntime` seam.
|
|
9
|
+
*/
|
|
10
|
+
/** Bounded per-provider checkAuth probe; shared with task 004's provider picker. */
|
|
11
|
+
export const CHECK_AUTH_TIMEOUT_MS = 3000;
|
|
12
|
+
function runtimeOf(ctx, opts) {
|
|
13
|
+
return ctx.auth ?? defaultAuthRuntime(resolvePiAuthPaths(opts));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Probe one provider's auth status with a bounded timeout. A hang (e.g. a slow ambient probe:
|
|
17
|
+
* an AWS-profile or ADC-file check) degrades to `"unknown"` rather than blocking the whole
|
|
18
|
+
* command — or, for task 004, the provider picker.
|
|
19
|
+
*/
|
|
20
|
+
export async function checkAuthBounded(runtime, providerId, timeoutMs = CHECK_AUTH_TIMEOUT_MS) {
|
|
21
|
+
const { promise: timeout, resolve: resolveTimeout } = Promise.withResolvers();
|
|
22
|
+
const timer = setTimeout(() => resolveTimeout("unknown"), timeoutMs);
|
|
23
|
+
try {
|
|
24
|
+
return await Promise.race([runtime.checkAuth(providerId), timeout]);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function buildStatusRows(runtime) {
|
|
31
|
+
const providers = await runtime.listProviders();
|
|
32
|
+
const rows = await Promise.all(providers.map(async (p) => {
|
|
33
|
+
const status = await checkAuthBounded(runtime, p.id);
|
|
34
|
+
if (status === "unknown")
|
|
35
|
+
return { id: p.id, name: p.name, configured: "unknown" };
|
|
36
|
+
if (!status.configured)
|
|
37
|
+
return { id: p.id, name: p.name, configured: false };
|
|
38
|
+
return { id: p.id, name: p.name, configured: true, type: status.type, source: status.source };
|
|
39
|
+
}));
|
|
40
|
+
return rows.toSorted((a, b) => a.id.localeCompare(b.id));
|
|
41
|
+
}
|
|
42
|
+
function statusLabel(row) {
|
|
43
|
+
if (row.configured === "unknown")
|
|
44
|
+
return "unknown";
|
|
45
|
+
if (!row.configured)
|
|
46
|
+
return "not configured";
|
|
47
|
+
return row.type === "oauth" ? "oauth" : "api key";
|
|
48
|
+
}
|
|
49
|
+
function sourceLabel(row) {
|
|
50
|
+
if (row.configured !== true)
|
|
51
|
+
return "";
|
|
52
|
+
return row.source ?? "auth.json";
|
|
53
|
+
}
|
|
54
|
+
async function runAuthStatus(ctx, opts) {
|
|
55
|
+
const runtime = runtimeOf(ctx, opts);
|
|
56
|
+
const rows = await buildStatusRows(runtime);
|
|
57
|
+
if (opts.json) {
|
|
58
|
+
ctx.sink.write(JSON.stringify(rows.map((r) => ({
|
|
59
|
+
id: r.id,
|
|
60
|
+
name: r.name,
|
|
61
|
+
configured: r.configured,
|
|
62
|
+
type: r.type,
|
|
63
|
+
source: r.source,
|
|
64
|
+
}))));
|
|
65
|
+
return EXIT_OK;
|
|
66
|
+
}
|
|
67
|
+
ctx.sink.write(renderTable(rows.map((r) => ({
|
|
68
|
+
PROVIDER: r.id,
|
|
69
|
+
NAME: r.name,
|
|
70
|
+
STATUS: statusLabel(r),
|
|
71
|
+
SOURCE: sourceLabel(r),
|
|
72
|
+
})), ["PROVIDER", "NAME", "STATUS", "SOURCE"]));
|
|
73
|
+
ctx.sink.error(runtime.authPathLabel());
|
|
74
|
+
return EXIT_OK;
|
|
75
|
+
}
|
|
76
|
+
function unknownProviderMessage(providers, providerId) {
|
|
77
|
+
const validIds = providers.map((p) => p.id).join(", ");
|
|
78
|
+
return `Unknown provider "${providerId}". Valid ids: ${validIds}`;
|
|
79
|
+
}
|
|
80
|
+
async function runAuthLogout(ctx, opts, providerId) {
|
|
81
|
+
const runtime = runtimeOf(ctx, opts);
|
|
82
|
+
const providers = await runtime.listProviders();
|
|
83
|
+
if (!providers.some((p) => p.id === providerId)) {
|
|
84
|
+
ctx.sink.error(unknownProviderMessage(providers, providerId));
|
|
85
|
+
return EXIT_ERROR;
|
|
86
|
+
}
|
|
87
|
+
const before = await runtime.checkAuth(providerId);
|
|
88
|
+
await runtime.logout(providerId);
|
|
89
|
+
ctx.sink.write(before.configured
|
|
90
|
+
? `${providerId}: removed stored credential (${runtime.authPathLabel()}).`
|
|
91
|
+
: `${providerId}: nothing stored.`);
|
|
92
|
+
// Re-check *after* removal: while a stored credential exists, checkAuth() reports it, not an
|
|
93
|
+
// ambient one behind it — the ambient source only becomes visible once the stored one is gone.
|
|
94
|
+
const after = await runtime.checkAuth(providerId);
|
|
95
|
+
if (after.configured) {
|
|
96
|
+
const source = after.source ?? "an ambient source";
|
|
97
|
+
ctx.sink.write(`${providerId} is still configured via ${source} — logout does not remove it.`);
|
|
98
|
+
}
|
|
99
|
+
return EXIT_OK;
|
|
100
|
+
}
|
|
101
|
+
// ─── auth login ─────────────────────────────────────────────────────────────────
|
|
102
|
+
function supportedTypesLabel(provider) {
|
|
103
|
+
const types = [];
|
|
104
|
+
if (provider.canApiKeyLogin)
|
|
105
|
+
types.push("api_key");
|
|
106
|
+
if (provider.canOAuthLogin)
|
|
107
|
+
types.push("oauth");
|
|
108
|
+
return types.length > 0 ? types.join(", ") : "none";
|
|
109
|
+
}
|
|
110
|
+
function typeUnsupportedError(provider, type) {
|
|
111
|
+
const supported = type === "api_key" ? provider.canApiKeyLogin : provider.canOAuthLogin;
|
|
112
|
+
if (supported)
|
|
113
|
+
return undefined;
|
|
114
|
+
return `Provider "${provider.id}" does not support --type ${type}. Supported: ${supportedTypesLabel(provider)}.`;
|
|
115
|
+
}
|
|
116
|
+
function providerPickerLabel(provider, status) {
|
|
117
|
+
const methods = [];
|
|
118
|
+
if (provider.canApiKeyLogin)
|
|
119
|
+
methods.push("api key");
|
|
120
|
+
if (provider.canOAuthLogin)
|
|
121
|
+
methods.push(provider.oauthLoginLabel ?? "oauth");
|
|
122
|
+
const badges = [];
|
|
123
|
+
if (provider.oauthIsSubscription)
|
|
124
|
+
badges.push("subscription");
|
|
125
|
+
if (status !== "unknown" && status.configured)
|
|
126
|
+
badges.push("already configured");
|
|
127
|
+
const suffix = [
|
|
128
|
+
methods.length > 0 ? `(${methods.join(", ")})` : "",
|
|
129
|
+
badges.length > 0 ? `[${badges.join(", ")}]` : "",
|
|
130
|
+
]
|
|
131
|
+
.filter((s) => s.length > 0)
|
|
132
|
+
.join(" ");
|
|
133
|
+
return suffix.length > 0 ? `${provider.name} ${suffix}` : provider.name;
|
|
134
|
+
}
|
|
135
|
+
/** No-argument `login`: render a picker over every login-capable provider. */
|
|
136
|
+
async function pickProviderInteractively(runtime, providers, interaction) {
|
|
137
|
+
const statuses = await Promise.all(providers.map((p) => checkAuthBounded(runtime, p.id)));
|
|
138
|
+
const options = providers.map((p, i) => ({
|
|
139
|
+
id: p.id,
|
|
140
|
+
label: providerPickerLabel(p, statuses[i]),
|
|
141
|
+
}));
|
|
142
|
+
const selectedId = await interaction.prompt({
|
|
143
|
+
type: "select",
|
|
144
|
+
message: "Select a provider to log in",
|
|
145
|
+
options,
|
|
146
|
+
});
|
|
147
|
+
return providers.find((p) => p.id === selectedId);
|
|
148
|
+
}
|
|
149
|
+
/** `--type` given → use it (pre-validated). One method → no prompt. Both → one select prompt. */
|
|
150
|
+
async function resolveLoginMethod(provider, interaction) {
|
|
151
|
+
if (provider.canApiKeyLogin && !provider.canOAuthLogin)
|
|
152
|
+
return "api_key";
|
|
153
|
+
if (provider.canOAuthLogin && !provider.canApiKeyLogin)
|
|
154
|
+
return "oauth";
|
|
155
|
+
const chosen = await interaction.prompt({
|
|
156
|
+
type: "select",
|
|
157
|
+
message: `How would you like to authenticate with ${provider.name}?`,
|
|
158
|
+
options: [
|
|
159
|
+
{ id: "api_key", label: "API key" },
|
|
160
|
+
{ id: "oauth", label: provider.oauthLoginLabel ?? "OAuth" },
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
return chosen === "oauth" ? "oauth" : "api_key";
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* `auth login [provider] [--type api_key|oauth] [--api-key K]` (features/provider-auth-cli.md
|
|
167
|
+
* § Behavior & Algorithms — `authLogin`, § Error Handling & Edge Cases). Exported so tests can
|
|
168
|
+
* drive it directly with a fake `TerminalIo`, bypassing Commander. `io` is left unresolved (no
|
|
169
|
+
* default-parameter expression) until *after* the flow's `AbortController` exists —
|
|
170
|
+
* `createTerminalIo()` needs it to map inquirer's Ctrl+C rejection (`ExitPromptError`) to a flow
|
|
171
|
+
* abort (inquirer traps SIGINT itself while a prompt is live; see auth-interaction.ts) — and only
|
|
172
|
+
* when the caller omits `io` at all and the flow actually needs terminal I/O (never for
|
|
173
|
+
* `--api-key`, which uses a prefilled interaction instead), so no prompt machinery — and no Pi
|
|
174
|
+
* import further down the call chain — is created at module load, registration, pre-flight-error,
|
|
175
|
+
* or headless-login time.
|
|
176
|
+
*/
|
|
177
|
+
export async function runAuthLogin(ctx, opts, providerArg, cmdOpts, io) {
|
|
178
|
+
if (cmdOpts.type && cmdOpts.type !== "api_key" && cmdOpts.type !== "oauth") {
|
|
179
|
+
ctx.sink.error(`Invalid --type "${cmdOpts.type}". Must be "api_key" or "oauth".`);
|
|
180
|
+
io?.close();
|
|
181
|
+
return EXIT_ERROR;
|
|
182
|
+
}
|
|
183
|
+
if (cmdOpts.apiKey !== undefined && cmdOpts.type === "oauth") {
|
|
184
|
+
ctx.sink.error("--api-key implies --type api_key; it cannot be combined with --type oauth.");
|
|
185
|
+
io?.close();
|
|
186
|
+
return EXIT_ERROR;
|
|
187
|
+
}
|
|
188
|
+
if (cmdOpts.apiKey !== undefined && !providerArg) {
|
|
189
|
+
ctx.sink.error("--api-key requires an explicit provider argument, e.g. `auth login openai --api-key K`.");
|
|
190
|
+
io?.close();
|
|
191
|
+
return EXIT_ERROR;
|
|
192
|
+
}
|
|
193
|
+
const requestedType = cmdOpts.apiKey !== undefined ? "api_key" : cmdOpts.type;
|
|
194
|
+
const controller = new AbortController();
|
|
195
|
+
const onSigint = () => controller.abort();
|
|
196
|
+
process.once("SIGINT", onSigint);
|
|
197
|
+
// Non-TTY guard: only the interactive path (no --api-key) needs a prompt at all, and only that
|
|
198
|
+
// path needs terminal I/O, so this is also the only branch that ever constructs `io` — resolved
|
|
199
|
+
// here, before the Pi runtime is touched at all, so the guard never pays for it either.
|
|
200
|
+
let actualIo;
|
|
201
|
+
if (cmdOpts.apiKey === undefined) {
|
|
202
|
+
actualIo = io ?? createTerminalIo(controller);
|
|
203
|
+
if (!actualIo.isTty) {
|
|
204
|
+
ctx.sink.error("Interactive login needs a TTY; use --api-key <key> with an explicit provider for a " +
|
|
205
|
+
"non-interactive setup (scripts, CI, provisioning). OAuth providers cannot be " +
|
|
206
|
+
"authenticated this way — they need a real interactive login.");
|
|
207
|
+
process.removeListener("SIGINT", onSigint);
|
|
208
|
+
actualIo.close();
|
|
209
|
+
return EXIT_ERROR;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const runtime = runtimeOf(ctx, opts);
|
|
213
|
+
const providers = await runtime.listProviders();
|
|
214
|
+
// Pre-flight (before any prompt): a known provider argument can be fully validated up front.
|
|
215
|
+
if (providerArg) {
|
|
216
|
+
const found = providers.find((p) => p.id === providerArg);
|
|
217
|
+
if (!found) {
|
|
218
|
+
ctx.sink.error(unknownProviderMessage(providers, providerArg));
|
|
219
|
+
process.removeListener("SIGINT", onSigint);
|
|
220
|
+
actualIo?.close();
|
|
221
|
+
return EXIT_ERROR;
|
|
222
|
+
}
|
|
223
|
+
if (requestedType) {
|
|
224
|
+
const err = typeUnsupportedError(found, requestedType);
|
|
225
|
+
if (err) {
|
|
226
|
+
ctx.sink.error(err);
|
|
227
|
+
process.removeListener("SIGINT", onSigint);
|
|
228
|
+
actualIo?.close();
|
|
229
|
+
return EXIT_ERROR;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const interaction = cmdOpts.apiKey !== undefined
|
|
234
|
+
? createApiKeyInteraction({
|
|
235
|
+
apiKey: cmdOpts.apiKey,
|
|
236
|
+
sink: ctx.sink,
|
|
237
|
+
signal: controller.signal,
|
|
238
|
+
})
|
|
239
|
+
: createTerminalInteraction({ io: actualIo, sink: ctx.sink, signal: controller.signal });
|
|
240
|
+
try {
|
|
241
|
+
const provider = providerArg
|
|
242
|
+
? providers.find((p) => p.id === providerArg)
|
|
243
|
+
: await pickProviderInteractively(runtime, providers, interaction);
|
|
244
|
+
// The picker path only learns the provider here, so --type validation against it is deferred.
|
|
245
|
+
if (!providerArg && requestedType) {
|
|
246
|
+
const err = typeUnsupportedError(provider, requestedType);
|
|
247
|
+
if (err) {
|
|
248
|
+
ctx.sink.error(err);
|
|
249
|
+
return EXIT_ERROR;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const type = requestedType ?? (await resolveLoginMethod(provider, interaction));
|
|
253
|
+
const credential = await runtime.login(provider.id, type, interaction);
|
|
254
|
+
ctx.sink.write(`${provider.id}: logged in (${credential.type}). Credential stored at ${runtime.authPathLabel()}.`);
|
|
255
|
+
ctx.sink.write("Agents pick this up automatically on their next spawn — no restart needed.");
|
|
256
|
+
return EXIT_OK;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
// `controller.signal.aborted` is authoritative for "the user cancelled": Pi's own login()
|
|
260
|
+
// implementation independently races `interaction.signal` (the documented "abort the whole
|
|
261
|
+
// flow" contract) and, on abort, throws its own generic AbortError — not our
|
|
262
|
+
// `AuthPromptAbortedError` — so recognizing only that class here would misreport a real
|
|
263
|
+
// cancellation as a login failure whenever Pi's own abort path wins the race.
|
|
264
|
+
if (controller.signal.aborted || error instanceof AuthPromptAbortedError) {
|
|
265
|
+
ctx.sink.error("login cancelled");
|
|
266
|
+
return EXIT_ERROR;
|
|
267
|
+
}
|
|
268
|
+
ctx.sink.error(errorMessage(error));
|
|
269
|
+
return EXIT_ERROR;
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
process.removeListener("SIGINT", onSigint);
|
|
273
|
+
actualIo?.close();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export function registerAuthCommands(program, ctx, setExit) {
|
|
277
|
+
const g = () => program.opts();
|
|
278
|
+
const auth = program.command("auth").description("manage model provider credentials");
|
|
279
|
+
auth
|
|
280
|
+
.command("status")
|
|
281
|
+
.description("show which model providers are configured, how, and from where")
|
|
282
|
+
.action(async () => {
|
|
283
|
+
setExit(await runAuthStatus(ctx, g()));
|
|
284
|
+
});
|
|
285
|
+
auth
|
|
286
|
+
.command("logout <provider>")
|
|
287
|
+
.description("remove a stored provider credential")
|
|
288
|
+
.action(async (provider) => {
|
|
289
|
+
setExit(await runAuthLogout(ctx, g(), provider));
|
|
290
|
+
});
|
|
291
|
+
auth
|
|
292
|
+
.command("login [provider]")
|
|
293
|
+
.description("log in to a model provider (interactive, or headless with --api-key)")
|
|
294
|
+
.option("--type <type>", "authentication method: api_key or oauth")
|
|
295
|
+
.option("--api-key <key>", "store this key non-interactively (requires a provider argument; visible in shell " +
|
|
296
|
+
"history and process listings)")
|
|
297
|
+
.action(async (provider, cmdOpts) => {
|
|
298
|
+
setExit(await runAuthLogin(ctx, g(), provider, cmdOpts));
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=auth-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-commands.js","sourceRoot":"","sources":["../src/auth-commands.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,yBAAyB,GAE1B,MAAM,uBAAuB,CAAC;AA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oBAAoB,CAClC,OAAgB,EAChB,GAAe,EACf,OAA+B;IAE/B,MAAM,CAAC,GAAG,GAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAiB,CAAC;IAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,mCAAmC,CAAC,CAAC;IAEtF,IAAI;SACD,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,gEAAgE,CAAC;SAC7E,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,OAAO,CAAC,MAAM,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEL,IAAI;SACD,OAAO,CAAC,mBAAmB,CAAC;SAC5B,WAAW,CAAC,qCAAqC,CAAC;SAClD,MAAM,CAAC,KAAK,EAAE,QAAgB,EAAE,EAAE;QACjC,OAAO,CAAC,MAAM,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEL,IAAI;SACD,OAAO,CAAC,kBAAkB,CAAC;SAC3B,WAAW,CAAC,sEAAsE,CAAC;SACnF,MAAM,CAAC,eAAe,EAAE,yCAAyC,CAAC;SAClE,MAAM,CACL,iBAAiB,EACjB,mFAAmF;QACjF,+BAA+B,CAClC;SACA,MAAM,CAAC,KAAK,EAAE,QAA4B,EAAE,OAA2C,EAAE,EAAE;QAC1F,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { AuthInteractionLike } from "./auth-runtime.js";
|
|
2
|
+
import type { OutputSink } from "./output.js";
|
|
3
|
+
/**
|
|
4
|
+
* Terminal `AuthInteraction` (features/provider-auth-cli.md § Behavior & Algorithms — terminal
|
|
5
|
+
* interaction mapping table, § Error Handling). This is the entire UI adaptation layer over Pi's
|
|
6
|
+
* login contract: Pi owns all provider flow logic (API-key entry, OAuth, device codes, token
|
|
7
|
+
* exchange); this module only supplies `prompt`/`notify`. All prompt/notify output goes to
|
|
8
|
+
* **stderr** so `--json`-style stdout stays clean for scripting.
|
|
9
|
+
*
|
|
10
|
+
* Interactive rendering is `@inquirer/prompts` (arrow-key selects, type-to-filter search for long
|
|
11
|
+
* lists, masked password input) — lazy-imported inside `createTerminalIo()` so its module graph
|
|
12
|
+
* loads only when an interactive login actually begins, never for `--api-key`, `--help`, or any
|
|
13
|
+
* non-auth command.
|
|
14
|
+
*/
|
|
15
|
+
/** Rejects a pending/attempted prompt. `reason` distinguishes the two abort sources. */
|
|
16
|
+
export declare class AuthPromptAbortedError extends Error {
|
|
17
|
+
readonly reason: "flow" | "prompt" | "non-tty";
|
|
18
|
+
constructor(reason: "flow" | "prompt" | "non-tty");
|
|
19
|
+
}
|
|
20
|
+
/** Minimal terminal I/O seam so prompt/notify rendering is testable without a real TTY. */
|
|
21
|
+
export interface TerminalIo {
|
|
22
|
+
/** Echoed line input. */
|
|
23
|
+
question(query: string, signal?: AbortSignal): Promise<string>;
|
|
24
|
+
/** Masked input — the typed value is never echoed to the output stream. */
|
|
25
|
+
secret(query: string, signal?: AbortSignal): Promise<string>;
|
|
26
|
+
/** Interactive single-choice picker; resolves with the chosen option's `id`. */
|
|
27
|
+
select(message: string, options: readonly {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}[], signal?: AbortSignal): Promise<string>;
|
|
32
|
+
isTty: boolean;
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Default `TerminalIo`: `@inquirer/prompts` on `process.stdin`/`process.stderr`. Built on
|
|
37
|
+
* **stderr**, not stdout — prompt chrome and typed echo must never leak onto the channel `--json`
|
|
38
|
+
* scripting relies on staying clean (inquirer's `Context.output` carries every rendered byte).
|
|
39
|
+
*
|
|
40
|
+
* Takes the flow's own `AbortController` because inquirer traps Ctrl+C itself while a prompt is
|
|
41
|
+
* live (raw mode) — a process-level `'SIGINT'` listener never fires there. Inquirer surfaces it as
|
|
42
|
+
* an `ExitPromptError` rejection instead; `run()` below maps that to `controller.abort()` (so
|
|
43
|
+
* `runAuthLogin`'s authoritative `controller.signal.aborted` check reports a cancellation, not a
|
|
44
|
+
* failure) + `AuthPromptAbortedError("flow")`. Between prompts, `runAuthLogin`'s own
|
|
45
|
+
* `process.once("SIGINT", ...)` covers the gap. Programmatic aborts flow the other way: the merged
|
|
46
|
+
* per-prompt signal is threaded into inquirer's `Context.signal`, which tears the live prompt down
|
|
47
|
+
* (restoring the terminal) and rejects with its own `AbortPromptError` — `raceAbort()` outraces
|
|
48
|
+
* that with the correctly-tagged `AuthPromptAbortedError` either way.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createTerminalIo(controller: AbortController): TerminalIo;
|
|
51
|
+
/**
|
|
52
|
+
* Build a terminal-backed `AuthInteractionLike` for `AuthRuntime.login()`. `qr` defaults to
|
|
53
|
+
* `renderQrToTerminal`; overridable for tests (and so a failure never breaks the flow — QR
|
|
54
|
+
* rendering always degrades to URL-only output on error).
|
|
55
|
+
*
|
|
56
|
+
* `notify` is serialized through a queue and `prompt` awaits it before touching the terminal: Pi
|
|
57
|
+
* fires `notify({type:"auth_url"})` and `prompt(...)` back-to-back, and QR rendering is async —
|
|
58
|
+
* without this ordering the prompt query lands first and the QR splats onto the same line
|
|
59
|
+
* (observed live against a real OAuth flow).
|
|
60
|
+
*/
|
|
61
|
+
export declare function createTerminalInteraction(opts: {
|
|
62
|
+
io: TerminalIo;
|
|
63
|
+
sink: OutputSink;
|
|
64
|
+
signal: AbortSignal;
|
|
65
|
+
qr?: (text: string) => Promise<string>;
|
|
66
|
+
}): AuthInteractionLike;
|
|
67
|
+
/**
|
|
68
|
+
* Prefilled `AuthInteractionLike` for `auth login --api-key` (task-005, headless/scripted setup —
|
|
69
|
+
* CI, Dockerfiles, provisioning). A `secret` prompt resolves with `apiKey` immediately, with no
|
|
70
|
+
* terminal I/O and no echo; any other prompt kind means the provider needs real interactive login
|
|
71
|
+
* (e.g. OAuth device flow), which `--api-key` cannot satisfy — rejects with a clear message rather
|
|
72
|
+
* than hanging or silently misbehaving. `notify` events still render (progress/errors stay
|
|
73
|
+
* visible) via the same serialized `notifyFor` queue the terminal interaction uses.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createApiKeyInteraction(opts: {
|
|
76
|
+
apiKey: string;
|
|
77
|
+
sink: OutputSink;
|
|
78
|
+
signal: AbortSignal;
|
|
79
|
+
qr?: (text: string) => Promise<string>;
|
|
80
|
+
}): AuthInteractionLike;
|
|
81
|
+
//# sourceMappingURL=auth-interaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-interaction.d.ts","sourceRoot":"","sources":["../src/auth-interaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,mBAAmB,EAAkB,MAAM,mBAAmB,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;;;;;;;;GAWG;AAEH,wFAAwF;AACxF,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAE/C,YAAY,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,EAUhD;CACF;AAED,2FAA2F;AAC3F,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,2EAA2E;IAC3E,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,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