chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
43
third_party/pi/packages/ai/src/cli.ts
vendored
43
third_party/pi/packages/ai/src/cli.ts
vendored
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { createInterface } from "node:readline";
|
||||
import type { AuthPrompt, OAuthCredential, Provider } from "./index.ts";
|
||||
@@ -47,26 +48,30 @@ async function login(providerId: string): Promise<void> {
|
||||
if (!provider) throw new Error(`Unknown provider: ${providerId}`);
|
||||
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
||||
try {
|
||||
const credential = await provider.auth.oauth.login({
|
||||
signal: new AbortController().signal,
|
||||
prompt: (authPrompt) => answerPrompt(rl, authPrompt),
|
||||
notify: (event) => {
|
||||
switch (event.type) {
|
||||
case "auth_url":
|
||||
console.log(`\nOpen this URL in your browser:\n${event.url}`);
|
||||
if (event.instructions) console.log(event.instructions);
|
||||
break;
|
||||
case "device_code":
|
||||
console.log(`\nOpen this URL in your browser:\n${event.verificationUri}`);
|
||||
console.log(`Enter code: ${event.userCode}`);
|
||||
break;
|
||||
case "info":
|
||||
case "progress":
|
||||
console.log(event.message);
|
||||
break;
|
||||
}
|
||||
// This dev CLI does not persist an installation ID; apps should reuse one across logins.
|
||||
const credential = await provider.auth.oauth.login(
|
||||
{
|
||||
signal: new AbortController().signal,
|
||||
prompt: (authPrompt) => answerPrompt(rl, authPrompt),
|
||||
notify: (event) => {
|
||||
switch (event.type) {
|
||||
case "auth_url":
|
||||
console.log(`\nOpen this URL in your browser:\n${event.url}`);
|
||||
if (event.instructions) console.log(event.instructions);
|
||||
break;
|
||||
case "device_code":
|
||||
console.log(`\nOpen this URL in your browser:\n${event.verificationUri}`);
|
||||
console.log(`Enter code: ${event.userCode}`);
|
||||
break;
|
||||
case "info":
|
||||
case "progress":
|
||||
console.log(event.message);
|
||||
break;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
{ getDeviceId: randomUUID },
|
||||
);
|
||||
const auth = loadAuth();
|
||||
auth[providerId] = credential;
|
||||
saveAuth(auth);
|
||||
|
||||
Reference in New Issue
Block a user